0

I am trying to create a configuration form for my test Drupal 8 module. I have followed the instructions from the following tutorials:

https://www.drupal.org/docs/8/api/configuration-api/working-with-configuration-forms https://www.drupal.org/docs/8/api/form-api/configformbase-with-simple-configuration-api

Before I followed the instructions in these guides my module worked fine. However, after adding the form, I now get a WSOD when installing the module, with no error in the logs. I know that error reporting is on because I can make intentional mistakes in my module files and an error will be reported in the logs.

My question is: where have I gone wrong? It's hard to figure out a problem when you don't even have a stack trace to follow.

My company_info.routing.yml file:

company_info.content:
  path: '/company_info'
  defaults:
    _controller: '\Drupal\company_info\Controller\AdminController::content'
    _title: 'Hello World'
  requirements:
    _permission: 'access content'

company_info.admin_settings:
  path: '/admin/config/company_info'
  defaults:
    _form: '\Drupal\company_info\Form\AdminSettingsForm'
    _title: 'example'
  requirements:
    _permission: 'administer site configuration'

AdminSettingsForm.php:

<?php

namespace Drupal\company_info\Controller;

use Drupal\Core\Form\ConfigFormBase;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Form\FormStateInterface;

class AdminSettingsForm extends ConfigFormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'company_info_admin_settings';
  }

  /**
   * {@inheritdoc}
   */
  public function getEditableConfigNames() {
    return [
      'company_info.settings',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state, 
Request $request = NULL) {
    $config = $this->config('company_info.settings');

    $form['your_message'] = array(
      '#type' => 'textfield',
      '#title' => $this->t('Your Message!'),
      '#default_value' => $config->get('your_message'),
    );

    return parent::buildForm($form, $form_state);
  }

  /**
   *
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->config('company_info.settings')
      ->set('your_message', $form_state->getValues('your_message'))
      ->save();

  }
}

company_info.settings.yml

your_message: 'Default message here'
1

The namespace on your AdminSettingsForm class is incorrect.
It should be Drupal\company_info\Form;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.