class RulesReactionListBuilder in Rules 8.3
Defines a class to build a listing of ReactionRuleConfig entities.
Hierarchy
- class \Drupal\Core\Entity\EntityHandlerBase uses DependencySerializationTrait, StringTranslationTrait
- class \Drupal\Core\Entity\EntityListBuilder implements EntityHandlerInterface, EntityListBuilderInterface uses MessengerTrait, RedirectDestinationTrait
- class \Drupal\Core\Config\Entity\ConfigEntityListBuilder
- class \Drupal\rules\Controller\RulesReactionListBuilder
- class \Drupal\Core\Config\Entity\ConfigEntityListBuilder
- class \Drupal\Core\Entity\EntityListBuilder implements EntityHandlerInterface, EntityListBuilderInterface uses MessengerTrait, RedirectDestinationTrait
Expanded class hierarchy of RulesReactionListBuilder
See also
\Drupal\rules\Entity\ReactionRuleConfig
\Drupal\views_ui\ViewListBuilder
File
- src/
Controller/ RulesReactionListBuilder.php, line 19
Namespace
Drupal\rules\ControllerView source
class RulesReactionListBuilder extends ConfigEntityListBuilder {
/**
* The Rules event plugin manager.
*
* @var \Drupal\Core\RulesEventManager
*/
protected $eventManager;
/**
* Constructs a new RulesReactionListBuilder object.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The entity storage class.
* @param \Drupal\Core\RulesEventManager $eventManager
* The Rules event plugin manager.
*/
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, RulesEventManager $eventManager) {
parent::__construct($entity_type, $storage);
// Disable the pager because this list builder uses client-side filters,
// which requires all entities to be listed.
$this->limit = FALSE;
$this->eventManager = $eventManager;
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($entity_type, $container
->get('entity_type.manager')
->getStorage($entity_type
->id()), $container
->get('plugin.manager.rules_event'));
}
/**
* {@inheritdoc}
*/
public function load() {
$entities = [
'enabled' => [],
'disabled' => [],
];
foreach (parent::load() as $entity) {
if ($entity
->status()) {
$entities['enabled'][] = $entity;
}
else {
$entities['disabled'][] = $entity;
}
}
return $entities;
}
/**
* {@inheritdoc}
*
* Building the header and content lines for the reaction rules list.
*
* Calling the parent::buildHeader() adds a column for the possible actions
* and inserts the 'edit' and 'delete' links as defined for the entity type.
*/
public function buildHeader() {
$header['label'] = $this
->t('Reaction Rule');
$header['event'] = $this
->t('Event');
$header['description'] = $this
->t('Description');
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$event_names = $entity
->getEventNames();
$event_labels = [];
// List all Events that trigger this Rule.
foreach ($event_names as $event_name) {
$event_definition = $this->eventManager
->getDefinition($event_name);
$event_labels[] = $event_definition['label'];
}
/** @var \Drupal\rules\Entity\ReactionRuleConfig $entity */
$details = $this
->t('Machine name: @name', [
'@name' => $entity
->id(),
]);
if ($entity
->hasTags()) {
$details = $details . '<br />' . $this
->t('Tags: @tags', [
'@tags' => implode(', ', $entity
->getTags()),
]);
}
$row['label']['data-drupal-selector'] = 'rules-table-filter-text-source';
$row['label']['data'] = [
'#plain_text' => $entity
->label(),
'#suffix' => '<div class="description">' . $details . '</div>',
];
$row['event']['data-drupal-selector'] = 'rules-table-filter-text-source';
$row['event']['data'] = [
'#markup' => implode(",<br />", $event_labels),
];
$row['description']['data-drupal-selector'] = 'rules-table-filter-text-source';
$row['description']['data'] = [
'#type' => 'processed_text',
'#text' => $entity
->getDescription(),
'#format' => 'restricted_html',
];
return $row + parent::buildRow($entity);
}
/**
* {@inheritdoc}
*/
public function buildOperations(EntityInterface $entity) {
$build = parent::buildOperations($entity);
uasort($build['#links'], 'Drupal\\Component\\Utility\\SortArray::sortByWeightElement');
return $build;
}
/**
* {@inheritdoc}
*/
public function render() {
$build['description'] = [
'#prefix' => '<p>',
'#markup' => $this
->t('Reaction rules, listed below, react on selected events on the site. Each reaction rule may fire any number of <em>actions</em>, and may have any number of <em>conditions</em> that must be met for the actions to be executed. You can also set up <a href=":components">components</a> – stand-alone sets of Rules configuration that can be used in Rules and other parts of your site. See <a href=":documentation">the online documentation</a> for an introduction on how to use Rules.', [
':components' => Url::fromRoute('entity.rules_component.collection')
->toString(),
':documentation' => 'https://www.drupal.org/node/298480',
]),
'#suffix' => '</p>',
];
$entities = $this
->load();
$build['#type'] = 'container';
$build['#attributes']['id'] = 'rules-entity-list';
$build['#attached']['library'][] = 'core/drupal.ajax';
$build['#attached']['library'][] = 'rules/rules_ui.listing';
$build['filters'] = [
'#type' => 'container',
'#attributes' => [
'class' => [
'table-filter',
'js-show',
],
],
];
$build['filters']['text'] = [
'#type' => 'search',
'#title' => $this
->t('Filter'),
'#title_display' => 'invisible',
'#size' => 60,
'#placeholder' => $this
->t('Filter by rule name, machine name, event, description, or tag'),
'#attributes' => [
'class' => [
'rules-filter-text',
],
'data-table' => '.rules-listing-table',
'autocomplete' => 'off',
'title' => $this
->t('Enter a part of the rule name, machine name, event, description, or tag to filter by.'),
],
];
$build['enabled']['heading'] = [
'#prefix' => '<h2>',
'#markup' => $this
->t('Enabled', [], [
'context' => 'Plural',
]),
'#suffix' => '</h2>',
];
$build['disabled']['heading'] = [
'#prefix' => '<h2>',
'#markup' => $this
->t('Disabled', [], [
'context' => 'Plural',
]),
'#suffix' => '</h2>',
];
foreach ([
'enabled',
'disabled',
] as $status) {
$build[$status]['#type'] = 'container';
$build[$status]['#attributes'] = [
'class' => [
'rules-list-section',
$status,
],
];
$build[$status]['table'] = [
'#type' => 'table',
'#header' => $this
->buildHeader(),
'#attributes' => [
'class' => [
'rules-listing-table',
$status,
],
],
'#cache' => [
'contexts' => $this->entityType
->getListCacheContexts(),
'tags' => $this->entityType
->getListCacheTags(),
],
];
foreach ($entities[$status] as $entity) {
$build[$status]['table']['#rows'][$entity
->id()] = $this
->buildRow($entity);
}
}
$build['enabled']['table']['#empty'] = $this
->t('There are no enabled @label.', [
'@label' => $this->entityType
->getPluralLabel(),
]);
$build['disabled']['table']['#empty'] = $this
->t('There are no disabled @label.', [
'@label' => $this->entityType
->getPluralLabel(),
]);
return $build;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigEntityListBuilder:: |
public | function |
Gets this list's default operations. Overrides EntityListBuilder:: |
15 |
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 | |
EntityHandlerBase:: |
protected | property | The module handler to invoke hooks on. | 2 |
EntityHandlerBase:: |
protected | function | Gets the module handler. | 2 |
EntityHandlerBase:: |
public | function | Sets the module handler for this handler. | |
EntityListBuilder:: |
protected | property | Information about the entity type. | |
EntityListBuilder:: |
protected | property | The entity type ID. | |
EntityListBuilder:: |
protected | property | The number of entities to list per page, or FALSE to list all entities. | 3 |
EntityListBuilder:: |
protected | property | The entity storage class. | 1 |
EntityListBuilder:: |
protected | function | Ensures that a destination is present on the given URL. | |
EntityListBuilder:: |
protected | function | Loads entity IDs using a pager sorted by the entity id. | 4 |
EntityListBuilder:: |
protected | function | Gets the label of an entity. | |
EntityListBuilder:: |
public | function |
Provides an array of information to build a list of operation links. Overrides EntityListBuilderInterface:: |
2 |
EntityListBuilder:: |
public | function |
Gets the entity storage. Overrides EntityListBuilderInterface:: |
|
EntityListBuilder:: |
protected | function | Gets the title of the page. | 1 |
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. | |
RulesReactionListBuilder:: |
protected | property | The Rules event plugin manager. | |
RulesReactionListBuilder:: |
public | function |
Building the header and content lines for the reaction rules list. Overrides EntityListBuilder:: |
|
RulesReactionListBuilder:: |
public | function |
Builds a renderable list of operation links for the entity. Overrides EntityListBuilder:: |
|
RulesReactionListBuilder:: |
public | function |
Builds a row for an entity in the entity listing. Overrides EntityListBuilder:: |
|
RulesReactionListBuilder:: |
public static | function |
Instantiates a new instance of this entity handler. Overrides EntityListBuilder:: |
|
RulesReactionListBuilder:: |
public | function |
Loads entities of this type from storage for listing. Overrides ConfigEntityListBuilder:: |
|
RulesReactionListBuilder:: |
public | function |
Builds the entity listing as renderable array for table.html.twig. Overrides EntityListBuilder:: |
|
RulesReactionListBuilder:: |
public | function |
Constructs a new RulesReactionListBuilder object. Overrides EntityListBuilder:: |
|
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. |