class BackgroundImageSettingsForm in Background Image 8
Same name and namespace in other branches
- 2.x src/Form/BackgroundImageSettingsForm.php \Drupal\background_image\Form\BackgroundImageSettingsForm
- 2.0.x src/Form/BackgroundImageSettingsForm.php \Drupal\background_image\Form\BackgroundImageSettingsForm
Class BackgroundImageSettingsForm.
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\background_image\Form\BackgroundImageSettingsForm uses BackgroundImageFormTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of BackgroundImageSettingsForm
1 string reference to 'BackgroundImageSettingsForm'
File
- src/
Form/ BackgroundImageSettingsForm.php, line 17
Namespace
Drupal\background_image\FormView source
class BackgroundImageSettingsForm extends ConfigFormBase {
use BackgroundImageFormTrait;
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'background_image.settings',
];
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'background_image_settings';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$form['#attached']['library'][] = 'background_image/admin';
$inline_entity_form = \Drupal::moduleHandler()
->moduleExists('inline_entity_form');
$inline_entity_form_tip = $this
->t('The Inline Entity Form module is required to embed forms.');
$background_image_manager = BackgroundImageManager::service();
$supported_entity_types = $background_image_manager
->getSupportedEntityTypes();
$config = $this
->config('background_image.settings');
$form['vertical_tabs'] = [
'#type' => 'vertical_tabs',
];
// Enabled Entities.
$form['entities'] = [
'#group' => 'vertical_tabs',
'#type' => 'details',
'#title' => $this
->t('Entities'),
'#description' => $this
->t('Configure how entities and bundles are associated with background images. Only the "full" view mode of an entity will trigger the condition in which the associated background image will be used.'),
'#open' => TRUE,
];
if (!$inline_entity_form) {
$form['entities']['inline_entity_form']['#markup'] = t('If you wish to embed the background image form while editing an entity, you will need install the @inline_entity_form module.', [
'@inline_entity_form' => Link::fromTextAndUrl('Inline Entity Form', Url::fromUri('https://www.drupal.org/project/inline_entity_form'))
->toString(),
]);
}
// Iterate over each supported entity type.
$form['entities']['table'] = [
'#type' => 'table',
'#sticky' => TRUE,
'#attributes' => [
'class' => [
'entities',
],
],
'#header' => [
[
'data' => $this
->t('Entity/Bundle'),
],
[
'data' => $this
->t('Enable'),
'class' => [
'small',
],
],
[
'data' => $this
->t('Embed'),
'class' => [
'small',
],
],
[
'data' => $this
->t('Require'),
'class' => [
'small',
],
],
],
'#tree' => FALSE,
];
$rows = [];
foreach ($supported_entity_types as $type => $entity_type) {
$row = [];
$row[] = [
'data' => $entity_type
->getLabel(),
'colspan' => 5,
'class' => [
'entity-type',
],
];
$rows[] = $row;
if ($bundles = $background_image_manager
->getEntityTypeBundles($entity_type)) {
foreach ($bundles as $bundle => $info) {
$row = [];
$row[] = [
'data' => $info['label'],
'class' => [
'entity-bundle',
],
];
// Enable.
$form["entities-{$type}-{$bundle}-enable"] = [
'#type' => 'checkbox',
'#parents' => [
'entities',
$type,
$bundle,
'enable',
],
'#default_value' => !!$config
->get(implode('.', [
'entities',
$type,
$bundle,
'enable',
])),
];
// Embed/group.
$form["entities-{$type}-{$bundle}-embed"] = [
'#type' => 'container',
];
$form["entities-{$type}-{$bundle}-embed"]['embed'] = [
'#type' => 'checkbox',
'#parents' => [
'entities',
$type,
$bundle,
'embed',
],
'#default_value' => !!$config
->get(implode('.', [
'entities',
$type,
$bundle,
'embed',
])),
];
$form["entities-{$type}-{$bundle}-embed"]['group'] = [
'#type' => 'select',
'#parents' => [
'entities',
$type,
$bundle,
'group',
],
'#default_value' => $config
->get(implode('.', [
'entities',
$type,
$bundle,
'group',
])),
'#attributes' => [
'title' => $this
->t('The group in which the background image form will be embedded into (if it exists).'),
],
'#options' => [
'' => $this
->t('Default'),
'advanced' => $this
->t('Advanced'),
],
];
if (!$inline_entity_form) {
$form["entities-{$type}-{$bundle}-embed"]['embed']['#disabled'] = TRUE;
$form["entities-{$type}-{$bundle}-embed"]['embed']['#default_value'] = FALSE;
$form["entities-{$type}-{$bundle}-embed"]['embed']['#attributes']['title'] = $inline_entity_form_tip;
$form["entities-{$type}-{$bundle}-embed"]['group']['#disabled'] = TRUE;
$form["entities-{$type}-{$bundle}-embed"]['group']['#default_value'] = '';
}
else {
self::addState($form["entities-{$type}-{$bundle}-embed"]['embed'], [
'enabled',
], $form["entities-{$type}-{$bundle}-enable"], [
'*' => [
'checked' => TRUE,
],
]);
self::addState($form["entities-{$type}-{$bundle}-embed"]['group'], [
'enabled',
], $form["entities-{$type}-{$bundle}-enable"], [
'*' => [
'checked' => TRUE,
],
]);
self::addState($form["entities-{$type}-{$bundle}-embed"]['group'], [
'enabled',
], $form["entities-{$type}-{$bundle}-embed"], [
'*' => [
'checked' => TRUE,
],
]);
}
// Require
$form["entities-{$type}-{$bundle}-require"] = [
'#type' => 'checkbox',
'#parents' => [
'entities',
$type,
$bundle,
'require',
],
'#default_value' => !!$config
->get(implode('.', [
'entities',
$type,
$bundle,
'require',
])),
];
self::addState($form["entities-{$type}-{$bundle}-require"], [
'enabled',
], $form["entities-{$type}-{$bundle}-enable"], [
'*' => [
'checked' => TRUE,
],
]);
// Add the form elements to the row.
foreach ([
'enable',
'embed',
'require',
] as $property) {
$row[] = [
'data' => &$form["entities-{$type}-{$bundle}-{$property}"],
'class' => [
'small',
],
];
$form["entities-{$type}-{$bundle}-{$property}"]['#printed'] = TRUE;
}
// Add the row to the rows.
$rows[] = $row;
}
}
}
$form['entities']['table']['#rows'] = $rows;
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$this
->config('background_image.settings')
->merge(array_filter($form_state
->cleanValues()
->getValues()))
->save();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BackgroundImageFormTrait:: |
protected static | property | ||
BackgroundImageFormTrait:: |
protected static | property | ||
BackgroundImageFormTrait:: |
protected | property | ||
BackgroundImageFormTrait:: |
protected | property | ||
BackgroundImageFormTrait:: |
protected | property | ||
BackgroundImageFormTrait:: |
protected | property | ||
BackgroundImageFormTrait:: |
protected | property | ||
BackgroundImageFormTrait:: |
protected static | property | ||
BackgroundImageFormTrait:: |
protected static | property | ||
BackgroundImageFormTrait:: |
public static | function | Provides a way to add #states to an element, but in a deferred way. | |
BackgroundImageFormTrait:: |
public static | function | Adds a "Browse available tokens" link to the specified element. | |
BackgroundImageFormTrait:: |
public static | function | Appends a callback to an element. | |
BackgroundImageFormTrait:: |
public static | function | Filters a nested array recursively, from the bottom up. | |
BackgroundImageFormTrait:: |
public static | function | Attaches a submit handler to the given form. | |
BackgroundImageFormTrait:: |
public static | function | Attaches a submit handler to the given form. | |
BackgroundImageFormTrait:: |
public static | function | Creates a new group in the form, assigning child elements as needed. | |
BackgroundImageFormTrait:: |
public static | function | Retrieves first available #input element, going through children if needed. | |
BackgroundImageFormTrait:: |
public static | function | Retrieves the Background Image Manager service. | |
BackgroundImageFormTrait:: |
public static | function | Retrieves default element info or a property from it. | |
BackgroundImageFormTrait:: |
public static | function | Retrieves the Element Info Manager service. | |
BackgroundImageFormTrait:: |
public | function | Retrieves a subform value. | |
BackgroundImageFormTrait:: |
public | function | ||
BackgroundImageFormTrait:: |
public static | function | Retrieves the Token Entity Mapper service. | |
BackgroundImageFormTrait:: |
public | function |
Implements \Drupal\Core\Form\FormStateInterface::getValues() Overrides FormStateValuesTrait:: |
|
BackgroundImageFormTrait:: |
public static | function | Retrieves existing instance or creates new one from form state. | |
BackgroundImageFormTrait:: |
public static | function | Retrieves existing instance or creates new one from form state. | |
BackgroundImageFormTrait:: |
public static | function | Retrieves existing instance or creates new one from form state. | |
BackgroundImageFormTrait:: |
public static | function | Recursively maps a selector for a set of #states conditions. | |
BackgroundImageFormTrait:: |
public static | function | Prepends a callback to an element. | |
BackgroundImageFormTrait:: |
public static | function | The #pre_render callback for ::addState. | |
BackgroundImageFormTrait:: |
public | function | Sets the form. | |
BackgroundImageFormTrait:: |
public | function | Sets the current FormState object. | |
BackgroundImageFormTrait:: |
public | function | Sets a subform element. | |
BackgroundImageFormTrait:: |
public | function | Sets the subform state, if one exists. | |
BackgroundImageFormTrait:: |
public | function | Implements \Drupal\Core\Form\FormStateInterface::setValue() | |
BackgroundImageFormTrait:: |
public | function | Implements \Drupal\Core\Form\FormStateInterface::setValues() | |
BackgroundImageFormTrait:: |
public static | function | Determines if the "token" module exists. | |
BackgroundImageFormTrait:: |
public | function | Implements \Drupal\Core\Form\FormStateInterface::unsetValue() | |
BackgroundImageSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
BackgroundImageSettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
BackgroundImageSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
BackgroundImageSettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
ConfigFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
13 |
ConfigFormBase:: |
public | function | Constructs a \Drupal\system\ConfigFormBase object. | 11 |
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 | |
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 |
FormStateValuesTrait:: |
public | function | Implements \Drupal\Core\Form\FormStateInterface::getValue() | |
FormStateValuesTrait:: |
public | function | Implements \Drupal\Core\Form\FormStateInterface::hasValue() | |
FormStateValuesTrait:: |
public | function | Implements \Drupal\Core\Form\FormStateInterface::isValueEmpty() | |
FormStateValuesTrait:: |
public | function | Implements \Drupal\Core\Form\FormStateInterface::setValue() | |
FormStateValuesTrait:: |
public | function | Implements \Drupal\Core\Form\FormStateInterface::setValueForElement() | |
FormStateValuesTrait:: |
public | function | Implements \Drupal\Core\Form\FormStateInterface::setValues() | |
FormStateValuesTrait:: |
public | function | Implements \Drupal\Core\Form\FormStateInterface::unsetValue() | |
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. |