You are here

protected function FieldCollectionLinksFormatter::getAddLink in Field collection 8.3

Same name and namespace in other branches
  1. 8 src/Plugin/Field/FieldFormatter/FieldCollectionLinksFormatter.php \Drupal\field_collection\Plugin\Field\FieldFormatter\FieldCollectionLinksFormatter::getAddLink()
2 calls to FieldCollectionLinksFormatter::getAddLink()
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 47

Class

FieldCollectionLinksFormatter

Namespace

Drupal\field_collection\Plugin\Field\FieldFormatter

Code

protected function getAddLink(ContentEntityInterface $host) {
  $link = '';
  if ($host
    ->access('update', \Drupal::currentUser())) {
    $link = '<ul class="action-links action-links-field-collection-add"><li>';
    $link .= Link::fromTextAndUrl(t('Add'), Url::FromRoute('field_collection_item.add_page', [
      'field_collection' => $this->fieldDefinition
        ->getName(),
      'host_type' => $host
        ->getEntityTypeId(),
      'host_id' => $host
        ->id(),
    ]))
      ->toString();
    $link .= '</li></ul>';
  }
  return $link;
}