You are here

protected function ParagraphsWidget::duplicateButtonAccess in Paragraphs 8

Check duplicate button access.

Parameters

\Drupal\paragraphs\ParagraphInterface $paragraph: Paragraphs entity to check.

Return value

bool TRUE if we can duplicate the paragraph, otherwise FALSE.

1 call to ParagraphsWidget::duplicateButtonAccess()
ParagraphsWidget::formElement in src/Plugin/Field/FieldWidget/ParagraphsWidget.php
Uses a similar approach to populate a new translation.

File

src/Plugin/Field/FieldWidget/ParagraphsWidget.php, line 2725

Class

ParagraphsWidget
Plugin implementation of the 'entity_reference_revisions paragraphs' widget.

Namespace

Drupal\paragraphs\Plugin\Field\FieldWidget

Code

protected function duplicateButtonAccess(ParagraphInterface $paragraph) {
  if (!$this
    ->isFeatureEnabled('duplicate')) {
    return FALSE;
  }
  if (!$paragraph
    ->access('update')) {
    return FALSE;
  }
  if (!$this
    ->allowReferenceChanges()) {
    return FALSE;
  }
  $cardinality = $this->fieldDefinition
    ->getFieldStorageDefinition()
    ->getCardinality();

  // Hide the button if field cardinality is reached.
  return !($cardinality !== FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED && $this->realItemCount === $cardinality);
}