FlexiformFormEntityLoad.php in Flexiform 8
File
src/Plugin/FlexiformFormEntity/FlexiformFormEntityLoad.php
View source
<?php
namespace Drupal\flexiform\Plugin\FlexiformFormEntity;
use Drupal\Core\Form\FormStateInterface;
class FlexiformFormEntityLoad extends FlexiformFormEntityProvided {
public function getEntity() {
if (isset($this->configuration['id'])) {
$entity = $this->entityTypeManager
->getStorage($this
->getEntityType())
->load($this->configuration['id']);
return $this
->checkBundle($entity) ? $entity : NULL;
}
}
public function configurationForm(array $form, FormStateInterface $form_state) {
$form = parent::configurationForm($form, $form_state);
$form['id'] = [
'#type' => 'textfield',
'#title' => $this
->t('Entity ID'),
'#description' => $this
->t('The ID of the entity.'),
'#default_value' => !empty($this->configuration['id']) ? $this->configuration['id'] : '',
];
return $form;
}
}