function _ief_table_view_mode_add_extra_field in Inline Entity Form Table View Mode 8
Same name and namespace in other branches
- 8.2 ief_table_view_mode.module \_ief_table_view_mode_add_extra_field()
- 7 ief_table_view_mode.module \_ief_table_view_mode_add_extra_field()
Add a new extra field in the table of the UI.
Parameters
array $element: The element with all fields.
string $name: The machine name of the extra field.
array $table_field: The definition of the field from ief.
array $display: The view setting of the field.
\Drupal\Core\Entity\EntityDisplayBase $entity: The entity display.
\Drupal\field_ui\Form\EntityDisplayFormBase $formObject: The form object display form.
1 call to _ief_table_view_mode_add_extra_field()
- ief_table_view_mode_form_entity_view_display_edit_form_alter in ./
ief_table_view_mode.module - Implements hook_form_FORM_ID_alter() for entity_view_display_edit_form() form.
File
- ./
ief_table_view_mode.module, line 227 - Defines a view mode to set up the columns of the table for the IEF widget.
Code
function _ief_table_view_mode_add_extra_field(&$element, $field_id, $extra_field, $display, $entity, $formObject) {
$display_options = $entity
->getComponent($field_id);
$regions = array_keys($formObject
->getRegions());
$regions_options = $formObject
->getRegionOptions();
$label = $extra_field['label'] instanceof TranslatableMarkup ? $extra_field['label']
->render() : $extra_field['label'];
$element[$field_id] = array(
'#attributes' => array(
'class' => array(
'draggable',
'tabledrag-leaf',
),
),
'#row_type' => 'extra_field',
'#region_callback' => array(
$formObject,
'getRowRegion',
),
'#js_settings' => array(
'rowHandler' => 'field',
),
'human_name' => array(
'#markup' => $label . '*',
),
'weight' => array(
'#type' => 'textfield',
'#title' => \Drupal::translation()
->translate('Weight for @title', array(
'@title' => $label,
)),
'#title_display' => 'invisible',
'#default_value' => $display_options ? $display_options['weight'] : 0,
'#size' => 3,
'#attributes' => array(
'class' => array(
'field-weight',
),
),
),
'parent_wrapper' => array(
'parent' => array(
'#type' => 'select',
'#title' => \Drupal::translation()
->translate('Parents for @title', array(
'@title' => $label,
)),
'#title_display' => 'invisible',
'#options' => array_combine($regions, $regions),
'#empty_value' => '',
'#attributes' => array(
'class' => array(
'js-field-parent',
'field-parent',
),
),
'#parents' => array(
'fields',
$field_id,
'parent',
),
),
'hidden_name' => array(
'#type' => 'hidden',
'#default_value' => $field_id,
'#attributes' => array(
'class' => array(
'field-name',
),
),
),
),
'region' => [
'#type' => 'select',
'#title' => \Drupal::translation()
->translate('Region for @title', [
'@title' => $extra_field['label'],
]),
'#title_display' => 'invisible',
'#options' => $regions_options,
'#default_value' => $display_options ? $display_options['region'] : 'hidden',
'#attributes' => [
'class' => [
'field-region',
],
],
],
'plugin' => [
'type' => [
'#type' => 'hidden',
'#value' => $display_options ? 'visible' : 'hidden',
'#parents' => [
'fields',
$field_id,
'type',
],
'#attributes' => [
'class' => [
'field-plugin-type',
],
],
],
],
'settings_summary' => [],
'settings_edit' => [],
);
}