// Add the remaining columns.
$current['#header'][] = $this->t('Metadata');
- $current['#header'][] = ['data' => $this->t('Operations'), 'colspan' => 2];
+ $current['#header'][] = ['data' => $this->t('Operations'), 'colspan' => 3];
$current['#header'][] = $this->t('Order', [], ['context' => 'Sort order']);
/** @var \Drupal\file\FileInterface[] $entities */
$edit_button_access = $can_edit && $entity->access('update', $this->currentUser);
}
+ // The "Replace" button will only be shown if this setting is enabled in
+ // the widget, and there is only one entity in the current selection.
+ $replace_button_access = $this->getSetting('field_widget_replace') && (count($entities) === 1);
+
$entity_id = $entity->id();
// Find the default description.
'#attributes' => [
'data-entity-id' => $entity->getEntityTypeId() . ':' . $entity->id(),
'data-row-id' => $delta,
+ 'class' => ['edit-button'],
],
'#access' => $edit_button_access,
],
+ 'replace_button' => [
+ '#type' => 'submit',
+ '#value' => $this->t('Replace'),
+ '#ajax' => [
+ 'callback' => [get_class($this), 'updateWidgetCallback'],
+ 'wrapper' => $details_id,
+ ],
+ '#submit' => [[get_class($this), 'removeItemSubmit']],
+ '#name' => $field_machine_name . '_replace_' . $entity_id . '_' . md5(json_encode($field_parents)),
+ '#limit_validation_errors' => [array_merge($field_parents, [$field_machine_name, 'target_id'])],
+ '#attributes' => [
+ 'data-entity-id' => $entity->getEntityTypeId() . ':' . $entity->id(),
+ 'data-row-id' => $delta,
+ 'class' => ['replace-button'],
+ ],
+ '#access' => $replace_button_access,
+ ],
'remove_button' => [
'#type' => 'submit',
'#value' => $this->t('Remove'),
'#attributes' => [
'data-entity-id' => $entity->getEntityTypeId() . ':' . $entity->id(),
'data-row-id' => $delta,
+ 'class' => ['remove-button'],
],
'#access' => (bool) $widget_settings['field_widget_remove'],
],