Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 9 |
CRAP | |
0.00% |
0 / 60 |
| ActionFormBase | |
0.00% |
0 / 1 |
|
0.00% |
0 / 9 |
156 | |
0.00% |
0 / 60 |
| __construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| create | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
| buildForm | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| form | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 30 |
|||
| exists | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| actions | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
| validateForm | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 5 |
|||
| submitForm | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 5 |
|||
| save | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
| <?php | |
| /** | |
| * @file | |
| * Contains \Drupal\action\ActionFormBase. | |
| */ | |
| namespace Drupal\action; | |
| use Drupal\Core\Entity\EntityForm; | |
| use Drupal\Core\Entity\EntityStorageInterface; | |
| use Drupal\Core\Form\FormStateInterface; | |
| use Drupal\Core\Plugin\PluginFormInterface; | |
| use Symfony\Component\DependencyInjection\ContainerInterface; | |
| /** | |
| * Provides a base form for action forms. | |
| */ | |
| abstract class ActionFormBase extends EntityForm { | |
| /** | |
| * The action plugin being configured. | |
| * | |
| * @var \Drupal\Core\Action\ActionInterface | |
| */ | |
| protected $plugin; | |
| /** | |
| * The action storage. | |
| * | |
| * @var \Drupal\Core\Entity\EntityStorageInterface | |
| */ | |
| protected $storage; | |
| /** | |
| * Constructs a new action form. | |
| * | |
| * @param \Drupal\Core\Entity\EntityStorageInterface $storage | |
| * The action storage. | |
| */ | |
| public function __construct(EntityStorageInterface $storage) { | |
| $this->storage = $storage; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public static function create(ContainerInterface $container) { | |
| return new static( | |
| $container->get('entity.manager')->getStorage('action') | |
| ); | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function buildForm(array $form, FormStateInterface $form_state) { | |
| $this->plugin = $this->entity->getPlugin(); | |
| return parent::buildForm($form, $form_state); | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function form(array $form, FormStateInterface $form_state) { | |
| $form['label'] = array( | |
| '#type' => 'textfield', | |
| '#title' => $this->t('Label'), | |
| '#default_value' => $this->entity->label(), | |
| '#maxlength' => '255', | |
| '#description' => $this->t('A unique label for this advanced action. This label will be displayed in the interface of modules that integrate with actions.'), | |
| ); | |
| $form['id'] = array( | |
| '#type' => 'machine_name', | |
| '#default_value' => $this->entity->id(), | |
| '#disabled' => !$this->entity->isNew(), | |
| '#maxlength' => 64, | |
| '#description' => $this->t('A unique name for this action. It must only contain lowercase letters, numbers and underscores.'), | |
| '#machine_name' => array( | |
| 'exists' => array($this, 'exists'), | |
| ), | |
| ); | |
| $form['plugin'] = array( | |
| '#type' => 'value', | |
| '#value' => $this->entity->get('plugin'), | |
| ); | |
| $form['type'] = array( | |
| '#type' => 'value', | |
| '#value' => $this->entity->getType(), | |
| ); | |
| if ($this->plugin instanceof PluginFormInterface) { | |
| $form += $this->plugin->buildConfigurationForm($form, $form_state); | |
| } | |
| return parent::form($form, $form_state); | |
| } | |
| /** | |
| * Determines if the action already exists. | |
| * | |
| * @param string $id | |
| * The action ID | |
| * | |
| * @return bool | |
| * TRUE if the action exists, FALSE otherwise. | |
| */ | |
| public function exists($id) { | |
| $action = $this->storage->load($id); | |
| return !empty($action); | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| protected function actions(array $form, FormStateInterface $form_state) { | |
| $actions = parent::actions($form, $form_state); | |
| unset($actions['delete']); | |
| return $actions; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function validateForm(array &$form, FormStateInterface $form_state) { | |
| parent::validateForm($form, $form_state); | |
| if ($this->plugin instanceof PluginFormInterface) { | |
| $this->plugin->validateConfigurationForm($form, $form_state); | |
| } | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function submitForm(array &$form, FormStateInterface $form_state) { | |
| parent::submitForm($form, $form_state); | |
| if ($this->plugin instanceof PluginFormInterface) { | |
| $this->plugin->submitConfigurationForm($form, $form_state); | |
| } | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function save(array $form, FormStateInterface $form_state) { | |
| $this->entity->save(); | |
| drupal_set_message($this->t('The action has been successfully saved.')); | |
| $form_state->setRedirect('entity.action.collection'); | |
| } | |
| } |