You are here

class EntityInlineTableViewModeForm in Inline Entity Form Table View Mode 8.2

Entity inline table view mode form handler.

Hierarchy

Expanded class hierarchy of EntityInlineTableViewModeForm

3 files declare their use of EntityInlineTableViewModeForm
IefTableViewModeTestTrait.php in tests/src/Traits/IefTableViewModeTestTrait.php
ief_table_view_mode.module in ./ief_table_view_mode.module
Defines a view mode to set up the columns of the table for the IEF widget.
ViewModeIefTableTest.php in tests/src/Functional/ViewModeIefTableTest.php

File

src/Form/EntityInlineTableViewModeForm.php, line 11

Namespace

Drupal\ief_table_view_mode\Form
View source
class EntityInlineTableViewModeForm extends EntityInlineForm {
  const IEF_TABLE_VIEW_MODE_NAME = 'ief_table';

  /**
   * {@inheritdoc}
   */
  public function getTableFields($bundles) {
    $fields = parent::getTableFields($bundles);
    $entity_type = $this->entityType
      ->id();
    foreach ($bundles as $bundle) {
      $display = EntityViewDisplay::load($entity_type . '.' . $bundle . '.' . self::IEF_TABLE_VIEW_MODE_NAME);
      if (!$display || !$display
        ->status()) {
        continue;
      }
      $old_fields = $fields;
      $fields = [];
      $field_definitions = $this->entityFieldManager
        ->getFieldDefinitions($entity_type, $bundle);

      // Checking fields instances.
      foreach ($field_definitions as $field_name => $field_definition) {
        if (!$field_definition
          ->isDisplayConfigurable('view')) {
          continue;
        }
        $display_options = $display
          ->getComponent($field_name);
        if (empty($display_options)) {
          continue;
        }
        $fields[$field_name] = [
          'type' => 'field',
          'label' => $field_definition
            ->getLabel(),
          'display_options' => $display_options,
          'weight' => $display_options['weight'],
        ];
      }

      // Default settings maybe has not registered any extra field.
      foreach ($old_fields as $old_field_name => $old_field) {
        if (isset($fields[$old_field_name])) {
          continue;
        }
        $display_options = $display
          ->getComponent($old_field_name);
        if (empty($display_options)) {
          continue;
        }
        $fields[$old_field_name] = $old_field;
        $fields[$old_field_name]['weight'] = $display_options['weight'];
      }
      $extra_fields = $this->entityFieldManager
        ->getExtraFields($entity_type, $bundle);
      $extra_fields = isset($extra_fields['display']) ? $extra_fields['display'] : [];
      foreach ($extra_fields as $extra_field_name => $extra_field) {
        $display_options = $display
          ->getComponent($extra_field_name);
        if (empty($display_options)) {
          continue;
        }
        $fields[$extra_field_name] = [
          'type' => 'callback',
          'label' => is_string($extra_field['label']) ? $extra_field['label'] : $extra_field['label']
            ->render(),
          'callback' => 'ief_table_view_mode_table_field_extra_field_callback',
          'callback_arguments' => [
            $extra_field_name,
          ],
          'weight' => $display_options['weight'],
        ];
      }
    }
    return $fields;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityInlineForm::$entityFieldManager protected property The entity field manager.
EntityInlineForm::$entityType protected property The entity type managed by this handler.
EntityInlineForm::$entityTypeManager protected property The entity type manager.
EntityInlineForm::$moduleHandler protected property Module handler service.
EntityInlineForm::buildEntity protected function Builds an updated entity object based upon the submitted form values.
EntityInlineForm::createInstance public static function Instantiates a new instance of this entity handler. Overrides EntityHandlerInterface::createInstance
EntityInlineForm::delete public function Delete permanently saved entities. Overrides InlineFormInterface::delete
EntityInlineForm::entityForm public function Builds the entity form. Overrides InlineFormInterface::entityForm
EntityInlineForm::entityFormSubmit public function Handles the submission of an entity form. Overrides InlineFormInterface::entityFormSubmit
EntityInlineForm::entityFormValidate public function Validates the entity form. Overrides InlineFormInterface::entityFormValidate
EntityInlineForm::getEntityLabel public function Gets the label of the given entity. Overrides InlineFormInterface::getEntityLabel
EntityInlineForm::getEntityType public function Gets the entity type managed by this handler. Overrides InlineFormInterface::getEntityType
EntityInlineForm::getEntityTypeLabels public function Gets the entity type labels (singular, plural). Overrides InlineFormInterface::getEntityTypeLabels 1
EntityInlineForm::getFormDisplay protected function Gets the form display for the given entity.
EntityInlineForm::isTableDragEnabled public function Checks whether tabledrag should be enabled for the given table. Overrides InlineFormInterface::isTableDragEnabled
EntityInlineForm::save public function Saves the given entity. Overrides InlineFormInterface::save
EntityInlineForm::submitCleanFormState public static function Cleans up the form state for a submitted entity form.
EntityInlineForm::__construct public function Constructs the inline entity form controller.
EntityInlineTableViewModeForm::getTableFields public function Gets the columns used to represent an entity in the IEF table. Overrides EntityInlineForm::getTableFields
EntityInlineTableViewModeForm::IEF_TABLE_VIEW_MODE_NAME constant
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.