protected function InlineEntityFormComplex::buildRemoveForm in Inline Entity Form 8
Builds remove form.
Parameters
array $form: Form array structure.
1 call to InlineEntityFormComplex::buildRemoveForm()
- InlineEntityFormComplex::formElement in src/
Plugin/ Field/ FieldWidget/ InlineEntityFormComplex.php - Returns the form for a single field widget.
File
- src/
Plugin/ Field/ FieldWidget/ InlineEntityFormComplex.php, line 781
Class
- InlineEntityFormComplex
- Complex inline widget.
Namespace
Drupal\inline_entity_form\Plugin\Field\FieldWidgetCode
protected function buildRemoveForm(&$form) {
/** @var \Drupal\Core\Entity\EntityInterface $entity */
$entity = $form['#entity'];
$entity_id = $entity
->id();
$entity_label = $this->inlineFormHandler
->getEntityLabel($entity);
$labels = $this
->getEntityTypeLabels();
if ($entity_label) {
$message = $this
->t('Are you sure you want to remove %label?', [
'%label' => $entity_label,
]);
}
else {
$message = $this
->t('Are you sure you want to remove this %entity_type?', [
'%entity_type' => $labels['singular'],
]);
}
$form['message'] = [
'#theme_wrappers' => [
'container',
],
'#markup' => $message,
];
if (!empty($entity_id) && $this
->getSetting('allow_existing') && $entity
->access('delete')) {
$form['delete'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Delete this @type_singular from the system.', [
'@type_singular' => $labels['singular'],
]),
];
}
// Build a deta suffix that's appended to button #name keys for uniqueness.
$delta = $form['#ief_id'] . '-' . $form['#ief_row_delta'];
// Add actions to the form.
$form['actions'] = [
'#type' => 'container',
'#weight' => 100,
];
$form['actions']['ief_remove_confirm'] = [
'#type' => 'submit',
'#value' => $this
->t('Remove'),
'#name' => 'ief-remove-confirm-' . $delta,
'#limit_validation_errors' => [
$form['#parents'],
],
'#ajax' => [
'callback' => 'inline_entity_form_get_element',
'wrapper' => 'inline-entity-form-' . $form['#ief_id'],
],
'#allow_existing' => $this
->getSetting('allow_existing'),
'#submit' => [
[
get_class($this),
'submitConfirmRemove',
],
],
'#ief_row_delta' => $form['#ief_row_delta'],
];
$form['actions']['ief_remove_cancel'] = [
'#type' => 'submit',
'#value' => $this
->t('Cancel'),
'#name' => 'ief-remove-cancel-' . $delta,
'#limit_validation_errors' => [],
'#ajax' => [
'callback' => 'inline_entity_form_get_element',
'wrapper' => 'inline-entity-form-' . $form['#ief_id'],
],
'#submit' => [
[
get_class($this),
'submitCloseRow',
],
],
'#ief_row_delta' => $form['#ief_row_delta'],
];
}