You are here

class ClaroExtrasSettingsForm in Claro Extras 1.0.x

Class ClaroExtrasSettingsForm.

Hierarchy

Expanded class hierarchy of ClaroExtrasSettingsForm

1 string reference to 'ClaroExtrasSettingsForm'
claro_extras.routing.yml in ./claro_extras.routing.yml
claro_extras.routing.yml

File

src/Form/ClaroExtrasSettingsForm.php, line 12

Namespace

Drupal\claro_extras\Form
View source
class ClaroExtrasSettingsForm extends ConfigFormBase {

  /**
   * Drupal\Core\Entity\EntityTypeManagerInterface definition.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    $instance = parent::create($container);
    $instance->entityTypeManager = $container
      ->get('entity_type.manager');
    return $instance;
  }

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

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

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this
      ->config('claro_extras.settings');
    $form['claro_extras_settings'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Claro extras settings'),
      '#collapsible' => FALSE,
      '#collapsed' => FALSE,
    ];
    $form['claro_extras_settings']['tabs'] = [
      '#type' => 'vertical_tabs',
      '#default_tab' => 'basic_tab',
    ];
    $form['claro_extras_settings']['basic_tab']['basic_settings'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Display settings'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#group' => 'tabs',
    ];
    $form['claro_extras_settings']['basic_tab']['basic_settings']['node_form_meta'] = [
      '#type' => 'item',
      '#markup' => '<div class="theme-settings-title">' . $this
        ->t("Node form meta block position") . '</div>',
    ];
    $node_form_meta_default_value = $config
      ->get('node_form_meta') ?? NULL;
    $form['claro_extras_settings']['basic_tab']['basic_settings']['node_form_meta'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Display block meta as vertical tabs'),
      '#description' => $this
        ->t('Use the checkbox to display the node meta block as vertical tabs and under the main node form.'),
      '#default_value' => $node_form_meta_default_value,
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    ];
    $form['claro_extras_settings']['basic_tab']['basic_settings']['node_breadcrumbs'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Node Edit Breadcrumb'),
      '#description' => $this
        ->t("Enable this if breadcrumbs show an erroneous 'node' breadcrumb link when editing a node."),
      '#default_value' => $config
        ->get('node_breadcrumbs'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    ];
    $form['claro_extras_settings']['basic_tab']['basic_settings']['enhance_paragraph_titles'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Enhance Paragraph titles'),
      '#description' => $this
        ->t('Improved Paragraph titles display.'),
      '#default_value' => $config
        ->get('enhance_paragraph_titles'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    ];
    $node_type = $this->entityTypeManager
      ->getStorage('node_type');
    $options = array_map(function ($node_type) {
      return $node_type
        ->label();
    }, $node_type
      ->loadMultiple());
    $default_value = $config
      ->get('node_form_meta_types') ?? [];
    $form['claro_extras_settings']['basic_tab']['basic_settings']['node_form_meta_types'] = [
      '#type' => 'checkboxes',
      '#title' => $this
        ->t('Select the content types'),
      '#description' => $this
        ->t('Select the content type on which display the node meta block as vertical tabs and under the main node form.'),
      '#default_value' => $default_value ? array_filter($default_value) : [],
      '#options' => $options,
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#states' => [
        'visible' => [
          ':input[name="node_form_meta"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
    ];
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form, $form_state);
    $values = $form_state
      ->getValues();
    $claro_extras_config = $this
      ->config('claro_extras.settings');
    theme_settings_convert_to_config($values, $claro_extras_config)
      ->save();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ClaroExtrasSettingsForm::$entityTypeManager protected property Drupal\Core\Entity\EntityTypeManagerInterface definition.
ClaroExtrasSettingsForm::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
ClaroExtrasSettingsForm::create public static function Instantiates a new instance of this class. Overrides ConfigFormBase::create
ClaroExtrasSettingsForm::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
ClaroExtrasSettingsForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
ClaroExtrasSettingsForm::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
ConfigFormBase::__construct public function Constructs a \Drupal\system\ConfigFormBase object. 16
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 3
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::configFactory protected function Gets the config factory for this form. 3
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route.
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 72
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.