You are here

public function AgreementEntity::render in Agreement 8.2

Same name and namespace in other branches
  1. 3.0.x src/Plugin/views/field/AgreementEntity.php \Drupal\agreement\Plugin\views\field\AgreementEntity::render()

Renders the field.

Parameters

\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.

Return value

string|\Drupal\Component\Render\MarkupInterface The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.

Overrides FieldPluginBase::render

File

src/Plugin/views/field/AgreementEntity.php, line 130

Class

AgreementEntity
Provides a field handler for agreement configuration entities.

Namespace

Drupal\agreement\Plugin\views\field

Code

public function render(ResultRow $values) {
  if (empty($this->options['display'])) {
    return parent::render($values);
  }
  $build = [];
  $props = [
    'id',
    'label',
    'path',
  ];
  $settings = $values->_agreement !== NULL ? $values->_agreement
    ->getSettings() : [];

  // Create rendered markup for each key enabled in display options.
  foreach ($this->options['display'] as $key) {
    $build[$key] = [
      '#markup' => '',
    ];
    if ($values->_agreement !== NULL) {
      if (in_array($key, $props)) {
        $build[$key]['#markup'] = $this
          ->sanitizeValue($values->_agreement
          ->get($key));
      }
      elseif ($key === 'roles') {
        $build[$key] = [
          '#type' => 'item_list',
          '#items' => $settings['roles'],
        ];
      }
      else {
        $build[$key]['#markup'] = $this
          ->sanitizeValue($settings[$key]);
      }
    }
  }
  return $build;
}