You are here

public function EntityFieldVariable::changeDetails in Business Rules 8

Same name and namespace in other branches
  1. 2.x src/Plugin/BusinessRulesVariable/EntityFieldVariable.php \Drupal\business_rules\Plugin\BusinessRulesVariable\EntityFieldVariable::changeDetails()

Change the variable details box.

Give a chance to each variable plugin to change the variable details row on Available Variables Box.

Parameters

\Drupal\business_rules\Entity\Variable $variable: The variable.

array $row: The row which contains the variable.

Overrides BusinessRulesVariablePlugin::changeDetails

File

src/Plugin/BusinessRulesVariable/EntityFieldVariable.php, line 60

Class

EntityFieldVariable
Class EntityValue.

Namespace

Drupal\business_rules\Plugin\BusinessRulesVariable

Code

public function changeDetails(Variable $variable, array &$row) {

  // Show a link to a help modal window.
  $content = '<ul>';
  $content .= '<li>' . t('To access a particular multi-value field such as target id, you can use <code>{{@variable_id[delta]}}</code> where "delta" is the delta value to get a one value or <code>{{@variable_id}}</code> to get an array of values;', [
    '@variable_id' => $variable
      ->id(),
  ]) . '</li>';
  $content .= '<li>' . t('To access a particular multi-value field label you can use <code>{{@variable_id[delta]->label}}</code> where "delta" is the delta value to get one label or <code>{{@variable_id->label}}</code> to get an array of labels;', [
    '@variable_id' => $variable
      ->id(),
  ]) . '</li>';
  $content .= '<li>' . t('If you are looping through this field and this field is NOT an entity reference, you can access the current value using <code>{{@variable_id->current}}</code>;', [
    '@variable_id' => $variable
      ->id(),
  ]) . '</li>';
  $content .= '<li>' . t('If you are looping through this field and this field IS an entity reference, you can use <code>{{@variable_id->current->id}}</code> to get the entity reference target id or <code>{{@variable_id->current->label}}</code> to get the entity reference label.', [
    '@variable_id' => $variable
      ->id(),
  ]) . '</li>';
  $content .= '</ul>';
  $keyvalue = $this->util
    ->getKeyValueExpirable('entity_filed_variable');
  $keyvalue
    ->set($variable
    ->id(), [
    '#markup' => $content,
  ]);
  $details_link = Link::createFromRoute(t('Click here to see how to use this variable.'), 'business_rules.ajax.modal', [
    'method' => 'nojs',
    'title' => t('Entity Field Variable Help'),
    'collection' => 'entity_filed_variable',
    'key' => $variable
      ->id(),
  ], [
    'attributes' => [
      'class' => [
        'use-ajax',
      ],
    ],
  ])
    ->toString();
  $row['description']['data']['#markup'] .= '<br>' . $details_link;
}