FormComponentBase.php in Flexiform 8
File
src/FormComponent/FormComponentBase.php
View source
<?php
namespace Drupal\flexiform\FormComponent;
use Drupal\Core\Form\FormStateInterface;
use Drupal\flexiform\FlexiformEntityFormDisplay;
use Drupal\flexiform\FormEntity\FlexiformFormEntityManager;
abstract class FormComponentBase implements FormComponentInterface {
protected $name = '';
protected $options = [];
protected $formEntityManager = NULL;
protected $formDisplay = NULL;
public function getFormEntityManager() {
return $this->formEntityManager;
}
public function setFormEntityManager(FlexiformFormEntityManager $manager) {
$this->formEntityManager = $manager;
return $this;
}
public function setFormDisplay(FlexiformEntityFormDisplay $form_display) {
$this->formDisplay = $form_display;
}
public function getFormDisplay() {
return $this->formDisplay;
}
public function getAdminLabel() {
if ($namespace = $this
->getEntityNamespace()) {
return $this->options['label'] . ' [' . $this
->getFormEntityManager()
->getFormEntity($namespace)
->getFormEntityContextDefinition()
->getLabel() . ']';
}
return $this->options['label'];
}
protected function getEntityNamespace() {
if (strpos($this->name, ':')) {
list($namespace, $component_id) = explode(':', $this->name, 2);
return $namespace;
}
return '';
}
public function __construct($name, array $options, FlexiformEntityFormDisplay $form_display) {
$this->name = $name;
$this->options = $options;
$this
->setFormDisplay($form_display);
}
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;
}
public function settingsSummary() {
}
public function settingsFormSubmit($values, array $form, FormStateInterface $form_state) {
return [
'settings' => [
'label' => $values['settings']['label'],
],
];
}
}