taxonomy_menu_sync-1.0.4/src/Form/TaxonomyMenuSyncSettingsForm.php

src/Form/TaxonomyMenuSyncSettingsForm.php
<?php

namespace Drupal\taxonomy_menu_sync\Form;

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * Create a new menu configurations.
 */
class TaxonomyMenuSyncSettingsForm extends ConfigFormBase {

  /**
   * Configuration name.
   */
  const string SETTINGS = 'taxonomy_menu_sync.settings';

  /**
   * {@inheritDoc}
   */
  protected function getEditableConfigNames() {
    return [
      static::SETTINGS,
    ];
  }

  /**
   * {@inheritDoc}
   */
  public function getFormId() {
    return 'taxonomy_menu_sync_settings';
  }

  /**
   * {@inheritDoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this->config(static::SETTINGS);

    $form['disable_menu_title'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Disable/hide menu title update'),
      '#description' => $this->t('Restrict user to update title of menu generated via sync(taxonomy terms -> menu).'),
      '#default_value' => $config->get('disable_menu_title') ?? FALSE,
    ];

    $form['disable_menu_parent'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Disable/hide menu parent update'),
      '#description' => $this->t('Restrict user to update parent of menu generated via sync(taxonomy terms -> menu).'),
      '#default_value' => $config->get('disable_menu_parent') ?? FALSE,
    ];

    $form['disable_menu_delete'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Disable/hide menu delete'),
      '#description' => $this->t('Restrict user to delete menu generated via sync(taxonomy terms -> menu).'),
      '#default_value' => $config->get('disable_menu_delete') ?? FALSE,
    ];

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

  /**
   * {@inheritDoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form, $form_state);
    $this->config(static::SETTINGS)
      ->setData($form_state->cleanValues()->getValues())
      ->save();
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc