protected function ParagraphsWidget::removeButtonAccess in Paragraphs 8
Check remove button access.
Parameters
\Drupal\paragraphs\ParagraphInterface $paragraph: Paragraphs entity to check.
Return value
bool TRUE if we can remove paragraph, otherwise FALSE.
1 call to ParagraphsWidget::removeButtonAccess()
- 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 2693
Class
- ParagraphsWidget
- Plugin implementation of the 'entity_reference_revisions paragraphs' widget.
Namespace
Drupal\paragraphs\Plugin\Field\FieldWidgetCode
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;
}