You are here

abstract class FormComponentBase in Flexiform 8

Provides the base form component plugin.

Hierarchy

Expanded class hierarchy of FormComponentBase

4 files declare their use of FormComponentBase
CustomTextComponent.php in src/Plugin/FormComponentType/CustomTextComponent.php
ExtraFieldComponent.php in src/Plugin/FormComponentType/ExtraFieldComponent.php
FieldWidgetComponent.php in src/Plugin/FormComponentType/FieldWidgetComponent.php
FormElementComponent.php in src/Plugin/FormComponentType/FormElementComponent.php

File

src/FormComponent/FormComponentBase.php, line 12

Namespace

Drupal\flexiform\FormComponent
View source
abstract class FormComponentBase implements FormComponentInterface {

  /**
   * The name of this component.
   *
   * @var string
   */
  protected $name = '';

  /**
   * The options supplied for this component.
   *
   * @var array
   */
  protected $options = [];

  /**
   * The form entity manager.
   *
   * @var \Drupal\flexiform\FormEntity\FlexiformFormEntityManager
   */
  protected $formEntityManager = NULL;

  /**
   * The form display.
   *
   * @var \Drupal\flexiform\FlexiformEntityFormDisplay
   */
  protected $formDisplay = NULL;

  /**
   * @return \Drupal\flexiform\FormEntity\FlexiformFormEntityManager
   */
  public function getFormEntityManager() {
    return $this->formEntityManager;
  }

  /**
   * @param FlexiformFormEntityManager $manager
   */
  public function setFormEntityManager(FlexiformFormEntityManager $manager) {
    $this->formEntityManager = $manager;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function setFormDisplay(FlexiformEntityFormDisplay $form_display) {
    $this->formDisplay = $form_display;
  }

  /**
   * {@inheritdoc}
   */
  public function getFormDisplay() {
    return $this->formDisplay;
  }

  /**
   * {@inheritdoc}
   */
  public function getAdminLabel() {
    if ($namespace = $this
      ->getEntityNamespace()) {
      return $this->options['label'] . ' [' . $this
        ->getFormEntityManager()
        ->getFormEntity($namespace)
        ->getFormEntityContextDefinition()
        ->getLabel() . ']';
    }
    return $this->options['label'];
  }

  /**
   * Get the entity namespace from the component name.
   */
  protected function getEntityNamespace() {
    if (strpos($this->name, ':')) {
      list($namespace, $component_id) = explode(':', $this->name, 2);
      return $namespace;
    }
    return '';
  }

  /**
   * {@inheritdoc}
   */
  public function __construct($name, array $options, FlexiformEntityFormDisplay $form_display) {
    $this->name = $name;
    $this->options = $options;
    $this
      ->setFormDisplay($form_display);
  }

  /**
   * {@inheritdoc}
   */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $settings_form['settings'] = [
      '#type' => 'container',
      'admin_label' => [
        '#type' => 'textfield',
        '#title' => t('Admin Label'),
        '#default_value' => $this->options['admin_label'],
      ],
    ];
    return $settings_form;
  }

  /**
   * {@inheritdoc}
   */
  public function settingsSummary() {
  }

  /**
   * {@inheritdoc}
   */
  public function settingsFormSubmit($values, array $form, FormStateInterface $form_state) {
    return [
      'settings' => [
        'label' => $values['settings']['label'],
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FormComponentBase::$formDisplay protected property The form display.
FormComponentBase::$formEntityManager protected property The form entity manager.
FormComponentBase::$name protected property The name of this component.
FormComponentBase::$options protected property The options supplied for this component.
FormComponentBase::getAdminLabel public function Get the admin label for the component. Overrides FormComponentInterface::getAdminLabel 4
FormComponentBase::getEntityNamespace protected function Get the entity namespace from the component name.
FormComponentBase::getFormDisplay public function
FormComponentBase::getFormEntityManager public function
FormComponentBase::setFormDisplay public function
FormComponentBase::setFormEntityManager public function
FormComponentBase::settingsForm public function Get the settings form. Overrides FormComponentInterface::settingsForm 4
FormComponentBase::settingsFormSubmit public function 4
FormComponentBase::settingsSummary public function Get the settings summary. Overrides FormComponentInterface::settingsSummary 4
FormComponentBase::__construct public function 3
FormComponentInterface::extractFormValues public function Extract the form values. 4
FormComponentInterface::render public function Render the element. 4