You are here

class FlagListsSettingForm in Flag Lists 4.0.x

Class FlaggingCollectionSettingsForm.

Hierarchy

Expanded class hierarchy of FlagListsSettingForm

1 string reference to 'FlagListsSettingForm'
flag_lists.routing.yml in ./flag_lists.routing.yml
flag_lists.routing.yml

File

src/Form/FlagListsSettingForm.php, line 19

Namespace

Drupal\flag_lists\Form
View source
class FlagListsSettingForm extends ConfigFormBase {

  /**
   * The Cache Tags Invalidator.
   *
   * @var \Drupal\Core\Cache\CacheTagsInvalidator
   *   The cache tags handler.
   */
  protected $cacheTagsInvalidator;

  /**
   * The Entity Type Manager.
   *
   * @var \Drupal\Core\EntityTypeManager
   *   The entity type manager.
   */
  protected $entityTypeManager;

  /**
   * The Entity Display Repository.
   *
   * @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
   *   The entity display repository.
   */
  protected $entityDisplayRepository;

  /**
   * {@inheritdoc}
   */
  public function __construct(ConfigFactoryInterface $config_factory, CacheTagsInvalidator $cache_tags_invalidator, EntityTypeManager $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository) {
    parent::__construct($config_factory);
    $this->cacheTagsInvalidator = $cache_tags_invalidator;
    $this->entityTypeManager = $entity_type_manager;
    $this->entityDisplayRepository = $entity_display_repository;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('config.factory'), $container
      ->get('cache_tags.invalidator'), $container
      ->get('entity_type.manager'), $container
      ->get('entity_display.repository'));
  }

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

  /**
   * Returns a unique string identifying the form.
   *
   * @return string
   *   The unique string identifying the form.
   */
  public function getFormId() {
    return 'flag_lists_settings_form';
  }

  /**
   * Form submission handler.
   *
   * @param array $form
   *   An associative array containing the structure of the form.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The current state of the form.
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this
      ->config('flag_lists.settings')
      ->set('hide_collections', $form_state
      ->getValue('hide_collections'))
      ->save();
    $this
      ->config('flag_lists.settings')
      ->set('hide_collections_in_displays', $form_state
      ->getValue('hide_collections_in_displays'))
      ->save();
    $this
      ->config('flag_lists.settings')
      ->set('hide_templates_in_displays', $form_state
      ->getValue('hide_templates_in_displays'))
      ->save();
    $clearCacheLink = Link::createFromRoute('cache', 'system.performance_settings')
      ->toString();
    $this
      ->messenger()
      ->addStatus($this
      ->t('If needed, please clear the @link!', [
      '@link' => $clearCacheLink,
    ]));

    // Only invalidating using the generic cache tag.
    $this->cacheTagsInvalidator
      ->invalidateTags([
      'config:entity_view_display_list',
    ]);
  }

  /**
   * Defines the settings form for Flagging collection entities.
   *
   * @param array $form
   *   An associative array containing the structure of the form.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The current state of the form.
   *
   * @return array
   *   Form definition array.
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this
      ->config('flag_lists.settings');
    $form['flag_settings'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Overview Settings'),
    ];
    $flagOverviewLink = Link::createFromRoute('Flag Overview', 'entity.flag.collection')
      ->toString();
    $form['flag_settings']['hide_collections'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Hide Flagging Collections in the @link.', [
        '@link' => $flagOverviewLink,
      ]),
      '#default_value' => $config
        ->get('hide_collections'),
      '#description' => $this
        ->t('Do you want to hide the Flagging Collections in the @link?', [
        '@link' => $flagOverviewLink,
      ]),
    ];
    $flagCollectionsInDisplayLink = Link::createFromRoute('Content Types Manage Display Forms', 'entity.node_type.collection')
      ->toString();
    $form['content_types'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Content Types Settings'),
    ];
    $form['content_types']['hide_collections_in_displays'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Hide Flagging Collections in the @link as well as for other entities.', [
        '@link' => $flagCollectionsInDisplayLink,
      ]),
      '#default_value' => $config
        ->get('hide_collections_in_displays'),
      '#description' => $this
        ->t('Do you want to hide the Flagging Collections in the @link as well as for other entities?', [
        '@link' => $flagCollectionsInDisplayLink,
      ]),
    ];
    $form['content_types']['hide_templates_in_displays'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Hide Flagging Templates in the @link as well as for other entities.', [
        '@link' => $flagCollectionsInDisplayLink,
      ]),
      '#default_value' => $config
        ->get('hide_templates_in_displays'),
      '#description' => $this
        ->t('Do you want to hide the Flagging Templates in the @link as well as for other entities?', [
        '@link' => $flagCollectionsInDisplayLink,
      ]),
    ];
    return parent::buildForm($form, $form_state);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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
FlagListsSettingForm::$cacheTagsInvalidator protected property The Cache Tags Invalidator.
FlagListsSettingForm::$entityDisplayRepository protected property The Entity Display Repository.
FlagListsSettingForm::$entityTypeManager protected property The Entity Type Manager.
FlagListsSettingForm::buildForm public function Defines the settings form for Flagging collection entities. Overrides ConfigFormBase::buildForm
FlagListsSettingForm::create public static function Instantiates a new instance of this class. Overrides ConfigFormBase::create
FlagListsSettingForm::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
FlagListsSettingForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
FlagListsSettingForm::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
FlagListsSettingForm::__construct public function Constructs a \Drupal\system\ConfigFormBase object. Overrides ConfigFormBase::__construct
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.