You are here

public function FieldCollectionViewsHandlerFieldHostEntityPath::render in Field Collection Views 8.5

Same name and namespace in other branches
  1. 6.x src/Plugin/views/field/FieldCollectionViewsHandlerFieldHostEntityPath.php \Drupal\field_collection_views\Plugin\views\field\FieldCollectionViewsHandlerFieldHostEntityPath::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/FieldCollectionViewsHandlerFieldHostEntityPath.php, line 49

Class

FieldCollectionViewsHandlerFieldHostEntityPath
Field handler to flag the field_collection_views_host_path.

Namespace

Drupal\field_collection_views\Plugin\views\field

Code

public function render(ResultRow $values) {
  $host_entity_path = "";
  $item_id = $values->item_id;
  $field_collection_item = FieldCollectionItem::load($item_id);
  $host_entity_id = $field_collection_item
    ->getHostId();
  if (!empty($host_entity_id)) {
    $host_entity_type = $field_collection_item
      ->get('host_type')->value;
    if (!empty($host_entity_type)) {
      $host_entitys = \Drupal::entityManager()
        ->getStorage($host_entity_type)
        ->load($host_entity_id);
      $host_entity_path = $host_entitys
        ->toUrl()
        ->toString();
    }
  }
  return $host_entity_path;
}