You are here

public function RulesReactionListBuilder::render in Rules 8.3

Builds the entity listing as renderable array for table.html.twig.

@todo Add a link to add a new item to the #empty text.

Overrides EntityListBuilder::render

File

src/Controller/RulesReactionListBuilder.php, line 140

Class

RulesReactionListBuilder
Defines a class to build a listing of ReactionRuleConfig entities.

Namespace

Drupal\rules\Controller

Code

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;
}