class EmergencyForm in Display Suite 8.2
Same name and namespace in other branches
- 8.4 src/Form/EmergencyForm.php \Drupal\ds\Form\EmergencyForm
- 8.3 src/Form/EmergencyForm.php \Drupal\ds\Form\EmergencyForm
Emergency form for DS.
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\ds\Form\EmergencyForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of EmergencyForm
1 string reference to 'EmergencyForm'
File
- src/
Form/ EmergencyForm.php, line 15
Namespace
Drupal\ds\FormView source
class EmergencyForm extends ConfigFormBase {
/**
* State object.
*
* @var \Drupal\Core\State\State
*/
protected $state;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Constructs a \Drupal\ds\Form\EmergencyForm object.
*
* @param \Drupal\Core\Config\ConfigFactory $config_factory
* The config factory.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\State\StateInterface $state
* The state key value store.
*/
public function __construct(ConfigFactory $config_factory, ModuleHandlerInterface $module_handler, StateInterface $state) {
parent::__construct($config_factory);
$this->moduleHandler = $module_handler;
$this->state = $state;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('module_handler'), $container
->get('state'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'ds_emergy_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['ds_fields_error'] = array(
'#type' => 'fieldset',
'#title' => $this
->t('Fields error'),
);
$form['ds_fields_error']['disable'] = array(
'#type' => 'html_tag',
'#tag' => 'p',
'#value' => $this
->t('In case you get an error after configuring a layout printing a message like "Fatal error: Unsupported operand types", you can temporarily disable adding fields from DS. You probably are trying to render an node inside a node, for instance through a view, which is simply not possible. See <a href="http://drupal.org/node/1264386">http://drupal.org/node/1264386</a>.'),
);
$form['ds_fields_error']['submit'] = array(
'#type' => 'submit',
'#value' => $this->state
->get('ds.disabled', FALSE) ? $this
->t('Enable attaching fields') : $this
->t('Disable attaching fields'),
'#submit' => array(
'::submitFieldAttach',
),
'#weight' => 1,
);
if ($this->moduleHandler
->moduleExists('ds_extras')) {
$region_blocks = $this
->config('ds_extras.settings')
->get('region_blocks');
if (!empty($region_blocks)) {
$region_blocks_options = array();
foreach ($region_blocks as $key => $info) {
$region_blocks_options[$key] = $info['title'];
}
$form['region_to_block'] = array(
'#type' => 'fieldset',
'#title' => $this
->t('Block regions'),
);
$form['region_to_block']['remove_block_region'] = array(
'#type' => 'checkboxes',
'#options' => $region_blocks_options,
'#description' => $this
->t('In case you renamed a content type, you will not see the configured block regions anymore, however the block on the block settings page is still available. On this screen you can remove orphaned block regions.'),
);
$form['region_to_block']['submit'] = array(
'#type' => 'submit',
'#value' => $this
->t('Remove block regions'),
'#submit' => array(
'::submitRegionToBlock',
),
'#weight' => 1,
);
}
}
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// empty.
}
/**
* Submit callback for the fields error form.
*/
public function submitFieldAttach(array &$form, FormStateInterface $form_state) {
$this->state
->set('ds.disabled', $this->state
->get('ds.disabled', FALSE) ? FALSE : TRUE);
drupal_set_message($this
->t('The configuration options have been saved.'));
}
/**
* Submit callback for the region to block form.
*/
public function submitRegionToBlock(array &$form, FormStateInterface $form_state) {
if ($form_state
->getValue('remove_block_region')) {
$save = FALSE;
$region_blocks = $this
->config('ds_extras.settings')
->get('region_blocks');
$remove = $form_state
->getValue('remove_block_region');
foreach ($remove as $key => $value) {
if ($value !== 0 && $key == $value) {
$save = TRUE;
// Make sure there is no active block instance for this ds block
// region.
if (\Drupal::moduleHandler()
->moduleExists('block')) {
$ids = \Drupal::entityQuery('block')
->condition('plugin', 'ds_region_block:' . $key)
->execute();
/* @var \Drupal\block\BlockInterface $block_storage */
$block_storage = \Drupal::service('entity_type.manager')
->getStorage('block');
foreach ($block_storage
->loadMultiple($ids) as $block) {
$block
->delete();
}
}
unset($region_blocks[$key]);
}
}
if ($save) {
drupal_set_message($this
->t('Block regions were removed.'));
// Clear cached block and ds plugin definitions.
\Drupal::service('plugin.manager.block')
->clearCachedDefinitions();
\Drupal::service('plugin.manager.ds')
->clearCachedDefinitions();
$this
->config('ds_extras.settings')
->set('region_blocks', $region_blocks)
->save();
}
}
else {
drupal_set_message($this
->t('No block regions were removed.'));
}
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return array(
'ds_extras.settings',
);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
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 | |
EmergencyForm:: |
protected | property | The module handler. | |
EmergencyForm:: |
protected | property | State object. | |
EmergencyForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
EmergencyForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
EmergencyForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
EmergencyForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
EmergencyForm:: |
public | function | Submit callback for the fields error form. | |
EmergencyForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
EmergencyForm:: |
public | function | Submit callback for the region to block form. | |
EmergencyForm:: |
public | function |
Constructs a \Drupal\ds\Form\EmergencyForm object. Overrides ConfigFormBase:: |
|
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 |
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. |