abstract class FormModeManagerFormBase in Form mode manager 8.2
Base for implementing system configuration forms for Form Mode Manager.
This abstract class allow you to play with all entities and form modes, without write ton of redondant code to loop on each entities compatible, with form mode manager and his form modes associated.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\form_mode_manager\Form\FormModeManagerFormBase
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of FormModeManagerFormBase
2 files declare their use of FormModeManagerFormBase
- FormModeManagerRolesForm.php in modules/
form_mode_user_roles_assign/ src/ Form/ FormModeManagerRolesForm.php - FormModeThemeSwitcherForm.php in modules/
form_mode_theme_switcher/ src/ Form/ FormModeThemeSwitcherForm.php
File
- src/
Form/ FormModeManagerFormBase.php, line 21
Namespace
Drupal\form_mode_manager\FormView source
abstract class FormModeManagerFormBase extends ConfigFormBase {
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The settings object.
*
* @var \Drupal\Core\Site\Settings
*/
protected $settings;
/**
* The entity display repository.
*
* @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
*/
protected $entityDisplayRepository;
/**
* The form_mode_manager service.
*
* @var \Drupal\form_mode_manager\FormModeManager
*/
protected $formModeManager;
/**
* The cache tags invalidator.
*
* @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface
*/
protected $cacheTagsInvalidator;
/**
* The form modes list to exclude are used or ignored.
*
* @var bool
*/
protected $ignoreExcluded;
/**
* Ignore Active display checks from list.
*
* @var bool
*/
protected $ignoreActiveDisplay;
/**
* Constructs a CropWidgetForm object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
* The entity display repository.
* @param \Drupal\form_mode_manager\FormModeManagerInterface $form_mode_manager
* The form_mode_manager service.
* @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tags_invalidator
* The cache tags invalidator.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityDisplayRepositoryInterface $entity_display_repository, FormModeManagerInterface $form_mode_manager, CacheTagsInvalidatorInterface $cache_tags_invalidator, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($config_factory);
$this->settings = $this
->getConfig();
$this->entityDisplayRepository = $entity_display_repository;
$this->formModeManager = $form_mode_manager;
$this->cacheTagsInvalidator = $cache_tags_invalidator;
$this->entityTypeManager = $entity_type_manager;
$this->ignoreExcluded = FALSE;
$this->ignoreActiveDisplay = TRUE;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('entity_display.repository'), $container
->get('form_mode.manager'), $container
->get('cache_tags.invalidator'), $container
->get('entity_type.manager'));
}
/**
* Retrieve the current class editable config name.
*
* @return \Drupal\Core\Config\Config|\Drupal\Core\Config\ImmutableConfig
* The setting object.
*/
protected function getConfig() {
return $this
->config(current($this
->getEditableConfigNames()));
}
/**
* Build Form Mode Manager settings form for each entity and form modes.
*
* This method implement use abstract buildFormPerEntity &,
* buildFormPerFormMode to take control of element you need for each,
* compatible entities and form modes used by Form Mode Manager module.
* You can use one or all methods to applies your own logic on all,
* entities/modes you need without code duplication.
*
* @param array $form
* An associative array containing the structure of the form.
*
* @return array
* The structure of the form populated.
*/
public function buildFormModeForm(array &$form) {
$form_modes = $this->formModeManager
->getAllFormModesDefinitions($this->ignoreExcluded, $this->ignoreActiveDisplay);
if (empty($form_modes)) {
$form['empty']['#markup'] = t('Any Form modes activated in form display found.');
return $form;
}
foreach (array_keys($form_modes) as $entity_type_id) {
$this
->buildFormPerEntity($form, $form_modes, $entity_type_id);
foreach ($form_modes[$entity_type_id] as $form_mode) {
$this
->buildFormPerFormMode($form, $form_mode, $entity_type_id);
}
}
return $form;
}
/**
* Set Form Mode Manager settings from form for each entity and form modes.
*
* This method implement use abstract buildSettingsPerEntity &,
* buildSettingsPerFormMode to take control of element you need,
* to save for all compatible entities and/or form modes.
*
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
public function setFormModeFormSettings(FormStateInterface $form_state) {
$form_modes = $this->formModeManager
->getAllFormModesDefinitions($this->ignoreExcluded, $this->ignoreActiveDisplay);
if (empty($form_modes)) {
return;
}
foreach (array_keys($form_modes) as $entity_type_id) {
$this
->setSettingsPerEntity($form_state, $form_modes, $entity_type_id);
foreach ($form_modes[$entity_type_id] as $form_mode) {
$this
->setSettingsPerFormMode($form_state, $form_mode, $entity_type_id);
}
}
}
/**
* Build form element per compatible entities.
*
* @param array $form
* An associative array containing the structure of the form.
* @param array $form_modes
* The form modes collection for given entity type.
* @param string $entity_type_id
* The entity type ID of entity.
*
* @return string
* The name of the theme
*/
public abstract function buildFormPerEntity(array &$form, array $form_modes, $entity_type_id);
/**
* Build form element per form modes linked by given entity type.
*
* @param array $form
* An associative array containing the structure of the form.
* @param array $form_mode
* The form mode definition.
* @param string $entity_type_id
* The entity type ID of entity.
*
* @return $this|false
* The form Object.
*/
public abstract function buildFormPerFormMode(array &$form, array $form_mode, $entity_type_id);
/**
* Set settings per compatible entities.
*
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
* @param array $form_modes
* The form modes collection for given entity type.
* @param string $entity_type_id
* The entity type ID of entity.
*
* @return $this|false
* The form Object.
*/
public abstract function setSettingsPerEntity(FormStateInterface $form_state, array $form_modes, $entity_type_id);
/**
* Set settings per form modes for a given entity type.
*
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
* @param array $form_mode
* The form mode definition.
* @param string $entity_type_id
* The entity type ID of entity.
*
* @return $this|false
* The form Object.
*/
public abstract function setSettingsPerFormMode(FormStateInterface $form_state, array $form_mode, $entity_type_id);
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$this
->buildFormModeForm($form);
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$this
->setFormModeFormSettings($form_state);
$this->settings
->save();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
ConfigFormBaseTrait:: |
abstract protected | function | Gets the configuration names that will be editable. | 32 |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
FormInterface:: |
public | function | Returns a unique string identifying the form. | 236 |
FormModeManagerFormBase:: |
protected | property | The cache tags invalidator. | |
FormModeManagerFormBase:: |
protected | property | The entity display repository. | |
FormModeManagerFormBase:: |
protected | property | The entity type manager service. | |
FormModeManagerFormBase:: |
protected | property | The form_mode_manager service. | |
FormModeManagerFormBase:: |
protected | property | Ignore Active display checks from list. | |
FormModeManagerFormBase:: |
protected | property | The form modes list to exclude are used or ignored. | |
FormModeManagerFormBase:: |
protected | property | The settings object. | |
FormModeManagerFormBase:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
4 |
FormModeManagerFormBase:: |
public | function | Build Form Mode Manager settings form for each entity and form modes. | |
FormModeManagerFormBase:: |
abstract public | function | Build form element per compatible entities. | 4 |
FormModeManagerFormBase:: |
abstract public | function | Build form element per form modes linked by given entity type. | 4 |
FormModeManagerFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
1 |
FormModeManagerFormBase:: |
protected | function | Retrieve the current class editable config name. | |
FormModeManagerFormBase:: |
public | function | Set Form Mode Manager settings from form for each entity and form modes. | |
FormModeManagerFormBase:: |
abstract public | function | Set settings per compatible entities. | 4 |
FormModeManagerFormBase:: |
abstract public | function | Set settings per form modes for a given entity type. | 4 |
FormModeManagerFormBase:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
4 |
FormModeManagerFormBase:: |
public | function |
Constructs a CropWidgetForm object. Overrides ConfigFormBase:: |
4 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |