You are here

private function ChangeFieldInfo::getRows in Business Rules 2.x

Same name and namespace in other branches
  1. 8 src/Plugin/BusinessRulesAction/ChangeFieldInfo.php \Drupal\business_rules\Plugin\BusinessRulesAction\ChangeFieldInfo::getRows()

Get the current fields on the variable array.

Parameters

\Drupal\business_rules\ItemInterface $item: The variable.

array $settings: The current setting to add rows.

1 call to ChangeFieldInfo::getRows()
ChangeFieldInfo::getSettingsForm in src/Plugin/BusinessRulesAction/ChangeFieldInfo.php
Return the form array.

File

src/Plugin/BusinessRulesAction/ChangeFieldInfo.php, line 175

Class

ChangeFieldInfo
Class ChangeFieldInfo.

Namespace

Drupal\business_rules\Plugin\BusinessRulesAction

Code

private function getRows(ItemInterface $item, array &$settings) {
  $fields = $item
    ->getSettings('fields');
  $availableFields = $this->util
    ->getBundleEditableFields($item
    ->getTargetEntityType(), $item
    ->getTargetBundle());
  if (count($fields)) {
    foreach ($fields as $key => $field) {
      $links['remove'] = [
        'title' => t('Remove'),
        'url' => Url::fromRoute('business_rules.plugins.action.change_field_info.remove_field', [
          'action' => $item
            ->id(),
          'field' => $field['id'],
          'method' => 'nojs',
        ], [
          'attributes' => [
            'class' => [
              'use-ajax',
            ],
          ],
        ]),
        'weight' => 1,
      ];
      $settings[$key] = [
        'field' => [
          '#type' => 'markup',
          '#markup' => $availableFields[$field['field']],
        ],
        'action' => [
          '#type' => 'markup',
          '#markup' => $this->actionOptions[$field['action']],
        ],
        'operations' => [
          '#type' => 'operations',
          '#links' => $links,
        ],
        '#attributes' => [
          'id' => 'field-' . $field['id'],
        ],
      ];
    }
  }
  $settings['new.field'] = [
    'field' => [
      '#type' => 'select',
      '#required' => FALSE,
      '#options' => array_merge([
        '' => t('-Select-'),
      ], $availableFields),
    ],
    'action' => [
      '#type' => 'select',
      '#required' => FALSE,
      '#options' => $this->actionOptions,
    ],
    'operations' => [
      '#type' => 'submit',
      '#value' => t('Add'),
      '#validate' => [
        get_class($this) . '::validateAddFieldForm',
      ],
      '#submit' => [
        get_class($this) . '::addFieldSubmit',
      ],
    ],
  ];
}