Check duplicate button access.
\Drupal\paragraphs\ParagraphInterface $paragraph: Paragraphs entity to check.
bool TRUE if we can duplicate the paragraph, otherwise FALSE.
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);
}