public function ConditionSetController::itemsTable in Business Rules 8
Same name and namespace in other branches
- 2.x src/Controller/ConditionSetController.php \Drupal\business_rules\Controller\ConditionSetController::itemsTable()
The items table.
Parameters
string $condition_id: The condition id.
string $method: The method name: ajax|nojs.
Return value
array|\Drupal\Core\Ajax\AjaxResponse Render array or AjaxResponse.
1 string reference to 'ConditionSetController::itemsTable'
File
- src/
Controller/ ConditionSetController.php, line 170
Class
- ConditionSetController
- Class ConditionSetController.
Namespace
Drupal\business_rules\ControllerCode
public function itemsTable($condition_id, $method) {
$condition = Condition::load($condition_id);
$this
->init($condition);
$table['#title'] = $this
->t('Add @label_plural on %condition', [
'%condition' => $condition
->label(),
'@label_plural' => $this->labelPlural,
]);
$table['#attached']['library'][] = 'system/drupal.system.modules';
$table['filters'] = [
'#type' => 'container',
'#attributes' => [
'class' => [
'table-filter',
'js-show',
],
],
];
$table['filters']['text'] = [
'#type' => 'search',
'#title' => $this
->t('Search'),
'#size' => 30,
'#placeholder' => $this
->t('Search for a @label key', [
'@label' => $this->label,
]),
'#attributes' => [
'class' => [
'table-filter-text',
],
'data-table' => '.searchable-list',
'autocomplete' => 'off',
'title' => $this
->t('Enter a part of the @label key to filter by.', [
'@label' => $this->label,
]),
],
];
$header = [
'label' => $this->label,
'id' => $this
->t('Machine Name'),
'type' => $this
->t('Type'),
'description' => $this
->t('Description'),
'operations' => $this
->t('Operations'),
'filter' => [
'data' => [
'#markup' => 'filter',
],
'style' => 'display: none',
],
];
$rows = [];
/** @var \Drupal\business_rules\Entity\Condition $item */
foreach ($this->items as $item) {
if (!in_array($item
->id(), array_keys($this->savedItems)) && $item
->id() != $condition
->id()) {
$listBuilder = $this->entityTypeManager
->getListBuilder($item
->getEntityTypeId());
$operations = $listBuilder
->buildOperations($item);
$search_string = $item
->label() . ' ' . $item
->id() . ' ' . $item
->getTypeLabel() . ' ' . $item
->getDescription();
$link = Link::createFromRoute($item
->label(), 'business_rules.condition_set.items.add', [
'condition_id' => $condition_id,
'item_id' => $item
->id(),
]);
$rows[$item
->id()] = [
'label' => [
'data' => $link,
],
'id' => [
'data' => [
'#markup' => $item
->id(),
],
],
'type' => [
'data' => [
'#markup' => $item
->getTypeLabel(),
],
],
'description' => [
'data' => [
'#markup' => $item
->getDescription(),
],
],
'operations' => [
'data' => $operations,
],
'filter' => [
'data' => [
[
'#markup' => '<span class="table-filter-text-source">' . $search_string . '</span>',
],
],
'style' => [
'display: none',
],
],
];
}
}
$table['business_rule_items'] = [
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#attributes' => [
'class' => [
'searchable-list',
],
],
];
if ($method == 'ajax') {
$table['#attached']['library'][] = 'core/drupal.dialog.ajax';
$options = [
'width' => '75%',
];
$title = $this
->t('Add @item', [
'@item' => $this->label,
]);
$response = new AjaxResponse();
$response
->addCommand(new OpenModalDialogCommand($title, $table, $options));
return $response;
}
else {
return $table;
}
}