You are here

protected function FieldCollectionLinksFormatter::getEditLinks in Field collection 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/Field/FieldFormatter/FieldCollectionLinksFormatter.php \Drupal\field_collection\Plugin\Field\FieldFormatter\FieldCollectionLinksFormatter::getEditLinks()

Helper function to get Edit and Delete links for an item.

2 calls to FieldCollectionLinksFormatter::getEditLinks()
FieldCollectionEditableFormatter::viewElements in src/Plugin/Field/FieldFormatter/FieldCollectionEditableFormatter.php
Builds a renderable array for a field value.
FieldCollectionListFormatter::viewElements in src/Plugin/Field/FieldFormatter/FieldCollectionListFormatter.php
TODO: Use $langcode.

File

src/Plugin/Field/FieldFormatter/FieldCollectionLinksFormatter.php, line 16

Class

FieldCollectionLinksFormatter

Namespace

Drupal\field_collection\Plugin\Field\FieldFormatter

Code

protected function getEditLinks(FieldItemInterface $item) {
  $links = '';
  if ($item
    ->getEntity()
    ->access('update', \Drupal::currentUser())) {
    $links = '(' . Link::fromTextAndUrl(t('Edit'), Url::FromRoute('entity.field_collection_item.edit_form', [
      'field_collection_item' => $item->value,
    ]))
      ->toString();
    $links .= '|' . Link::fromTextAndUrl(t('Delete'), Url::FromRoute('entity.field_collection_item.delete_form', [
      'field_collection_item' => $item->value,
    ]))
      ->toString();
    $links .= ')';
  }
  return $links;
}