You are here

public function BusinessRulesItemsController::init in Business Rules 2.x

Same name and namespace in other branches
  1. 8 src/Controller/BusinessRulesItemsController.php \Drupal\business_rules\Controller\BusinessRulesItemsController::init()

Init properties.

Parameters

string $item_type: The item type action|condition.

1 call to BusinessRulesItemsController::init()
BusinessRulesItemsController::itemsTable in src/Controller/BusinessRulesItemsController.php
The items table.

File

src/Controller/BusinessRulesItemsController.php, line 289

Class

BusinessRulesItemsController
Class BusinessRulesItemsController.

Namespace

Drupal\business_rules\Controller

Code

public function init($item_type) {
  $this->item = $item_type;
  try {
    $destination = stristr($_SERVER["HTTP_REFERER"], '/ajax/') ? [] : [
      'destination' => $_SERVER["HTTP_REFERER"],
    ];
  } catch (\Exception $e) {
    $destination = [];
  }
  switch ($this->item) {
    case 'condition':
      $this->label = $this
        ->t('Condition');
      $this->labelPlural = $this
        ->t('Conditions');
      $this->items = Condition::loadMultiple();
      $this->itemsName = 'conditions';
      $this->itemType = 'condition';
      $this->newItemButton = Link::createFromRoute($this
        ->t('Add Condition'), 'entity.business_rules_condition.add_form', $destination, [
        'attributes' => [
          'class' => [
            'button',
            'button-action',
            'button--primary',
            'button--small',
          ],
        ],
      ]);
      break;
    case 'action':
      $this->label = $this
        ->t('Action');
      $this->labelPlural = $this
        ->t('Actions');
      $this->items = Action::loadMultiple();
      $this->itemsName = 'actions';
      $this->itemType = 'action';
      $this->newItemButton = Link::createFromRoute($this
        ->t('Add Action'), 'entity.business_rules_action.add_form', $destination, [
        'attributes' => [
          'class' => [
            'button',
            'button-action',
            'button--primary',
            'button--small',
          ],
        ],
      ]);
      break;
  }
}