abstract class FormComponentBase in Flexiform 8
Provides the base form component plugin.
Hierarchy
- class \Drupal\flexiform\FormComponent\FormComponentBase implements FormComponentInterface
 
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\FormComponentView 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'],
      ],
    ];
  }
}