Check remove button access.
\Drupal\paragraphs\ParagraphInterface $paragraph: Paragraphs entity to check.
bool TRUE if we can remove paragraph, otherwise FALSE.
protected function removeButtonAccess(ParagraphInterface $paragraph) {
// Avoid checking delete access for new entities.
if (!$paragraph
->isNew() && !$paragraph
->access('delete')) {
return FALSE;
}
if (!$this
->allowReferenceChanges()) {
return FALSE;
}
$field_required = $this->fieldDefinition
->isRequired();
$allowed_types = $this
->getAllowedTypes();
$cardinality = $this->fieldDefinition
->getFieldStorageDefinition()
->getCardinality();
// Hide the button if field is required, cardinality is one and just one
// paragraph type is allowed.
if ($field_required && $cardinality == 1 && count($allowed_types) == 1) {
return FALSE;
}
return TRUE;
}