You are here

public function SectionId::render in Workbench Access 8

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/SectionId.php, line 65

Class

SectionId
Field handler to present the section assigned to the node.

Namespace

Drupal\workbench_access\Plugin\views\field

Code

public function render(ResultRow $values) {
  $value = '';
  if ($entity = $this
    ->getEntity($values)) {
    $scheme_id = $entity
      ->getSchemeId();
    $section_id = $entity
      ->get('section_id')->value;

    // @TODO: We need a helper method or service for this lookup.
    $scheme = \Drupal::entityTypeManager()
      ->getStorage('access_scheme')
      ->load($scheme_id)
      ->getAccessScheme();
    if ($section = $scheme
      ->load($section_id)) {
      if ($this->options['make_link'] && isset($section['path'])) {

        // Sigh. THe views handlers expect URLs in different formats.
        $this->options['alter']['url'] = Url::fromUserInput('/' . trim($section['path'], '/'));
        $this->options['alter']['make_link'] = TRUE;
      }
      if ($this->options['output_format'] == 'label') {
        $value = $this
          ->sanitizeValue($section['label']);
      }
      else {
        $value = $this
          ->sanitizeValue($section_id);
      }
    }
  }
  return $value;
}