class StylesOverviewForm in Paragraphs Collection 8
Provides a form for revision overview page.
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\paragraphs_collection\Form\StylesOverviewForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of StylesOverviewForm
File
- src/
Form/ StylesOverviewForm.php, line 13
Namespace
Drupal\paragraphs_collection\FormView source
class StylesOverviewForm extends ConfigFormBase {
/**
* The discovery service for style files.
*
* @var \Drupal\paragraphs_collection\StyleDiscoveryInterface
*/
protected $styleDiscovery;
/**
* Wrapper object for simple configuration from diff.settings.yml.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $config;
/**
* Constructs a RevisionOverviewForm object.
*
* @param \Drupal\paragraphs_collection\StyleDiscoveryInterface $style_discovery
* The discovery service for style files.
*/
public function __construct(StyleDiscoveryInterface $style_discovery) {
$this->config = $this
->config('paragraphs_collection.settings');
$this->styleDiscovery = $style_discovery;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('paragraphs_collection.style_discovery'));
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'paragraphs_collection.settings',
];
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'paragraphs_collection_styles_overview_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $grouped_styles = NULL) {
$group_options = $this->styleDiscovery
->getStyleGroupsLabel();
asort($group_options);
$empty_option = [
'' => '- All -',
];
$filters = [
'#type' => 'fieldset',
'#attributes' => [
'class' => [
'table-filter',
'js-show',
'form--inline',
],
'data-table' => '.paragraphs-collection-overview-table',
],
'#title' => $this
->t('Filter'),
];
$filters['group'] = [
'#type' => 'select',
'#title' => $this
->t('Group'),
'#options' => $empty_option + $group_options,
'#attributes' => [
'class' => [
'table-filter-group-select',
],
],
];
$filters['text'] = [
'#type' => 'search',
'#title' => $this
->t('Style label or ID'),
'#size' => 40,
'#attributes' => [
'class' => [
'table-filter-text',
],
'autocomplete' => 'off',
'title' => $this
->t('Enter a part of the style label or ID to filter by.'),
],
];
$header = [
'enabled' => $this
->t('Style'),
'details' => $this
->t('Details'),
'use' => $this
->t('Used in'),
];
$styles = $this->styleDiscovery
->getStyles();
$enabled_styles = $this->config
->get('enabled_styles');
$rows = [];
foreach ($grouped_styles as $style_id => $value) {
$style = $styles[$style_id];
$paragraphs_type_link_list = [];
foreach ($value as $paragraphs_type_id => $paragraphs_type) {
/** @var \Drupal\paragraphs\Entity\ParagraphsType $paragraphs_type */
if ($paragraphs_type_link_list != []) {
$paragraphs_type_link_list[] = [
'#plain_text' => ', ',
];
}
$paragraphs_type_link_list[] = [
'#type' => 'link',
'#title' => $paragraphs_type
->label(),
'#url' => $paragraphs_type
->toUrl(),
'#attributes' => [
'class' => [
'table-filter-paragraphs-type-source',
],
],
];
}
$group_list = [];
foreach ($style['groups'] as $group) {
if ($group_list != []) {
$group_list[] = [
'#plain_text' => ', ',
];
}
$group_list[] = [
'#type' => 'container',
'#plain_text' => $group,
'#attributes' => [
'class' => [
'table-filter-group-source',
],
],
];
}
$rows[$style_id]['enabled'] = array(
'#type' => 'checkbox',
'#title' => $style['title'],
'#title_display' => 'after',
'#default_value' => in_array($style_id, $enabled_styles) ?: FALSE,
);
$rows[$style_id]['details'] = [
'#type' => 'details',
'#title' => !empty($style['description']) ? $style['description'] : $this
->t('Description not available.'),
'#open' => FALSE,
'#attributes' => [
'class' => [
'overview-details',
],
],
];
$rows[$style_id]['details']['id'] = [
'#type' => 'item',
'#title' => $this
->t('ID'),
'#prefix' => '<span class="container-inline">',
'#suffix' => '</span>',
'item' => [
'#type' => 'container',
'#plain_text' => $style_id,
'#attributes' => [
'class' => [
'table-filter-text-source',
],
],
],
];
$rows[$style_id]['details']['groups'] = [
'#type' => 'item',
'#title' => $this
->t('Groups'),
'item' => $group_list,
'#prefix' => '<div class="container-inline">',
'#suffix' => '</div>',
];
$rows[$style_id]['use'] = $paragraphs_type_link_list;
}
$table = [
'#type' => 'table',
'#header' => $header,
'#sticky' => TRUE,
'#attributes' => [
'class' => [
'paragraphs-collection-overview-table',
],
],
];
$table += $rows;
$form['filters'] = $filters;
$form['styles'] = $table;
$form['#attached']['library'] = [
'paragraphs_collection/overview',
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$enabled_styles = array_keys(array_filter((array) $form_state
->getValue('styles'), function ($value) {
return !empty($value['enabled']);
}));
$this->config
->set('enabled_styles', $enabled_styles);
$this->config
->save();
}
}
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 | |
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. | |
StylesOverviewForm:: |
protected | property | Wrapper object for simple configuration from diff.settings.yml. | |
StylesOverviewForm:: |
protected | property | The discovery service for style files. | |
StylesOverviewForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
StylesOverviewForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
StylesOverviewForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
StylesOverviewForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
StylesOverviewForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
StylesOverviewForm:: |
public | function |
Constructs a RevisionOverviewForm object. Overrides ConfigFormBase:: |
|
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. |