Chris@0: storage = $storage; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function create(ContainerInterface $container) { Chris@0: return new static( Chris@0: $container->get('entity.manager')->getStorage('action') Chris@0: ); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function buildForm(array $form, FormStateInterface $form_state) { Chris@0: $this->plugin = $this->entity->getPlugin(); Chris@0: return parent::buildForm($form, $form_state); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function form(array $form, FormStateInterface $form_state) { Chris@0: $form['label'] = [ Chris@0: '#type' => 'textfield', Chris@0: '#title' => $this->t('Label'), Chris@0: '#default_value' => $this->entity->label(), Chris@0: '#maxlength' => '255', Chris@0: '#description' => $this->t('A unique label for this advanced action. This label will be displayed in the interface of modules that integrate with actions.'), Chris@0: ]; Chris@0: Chris@0: $form['id'] = [ Chris@0: '#type' => 'machine_name', Chris@0: '#default_value' => $this->entity->id(), Chris@0: '#disabled' => !$this->entity->isNew(), Chris@0: '#maxlength' => 64, Chris@0: '#description' => $this->t('A unique name for this action. It must only contain lowercase letters, numbers and underscores.'), Chris@0: '#machine_name' => [ Chris@0: 'exists' => [$this, 'exists'], Chris@0: ], Chris@0: ]; Chris@0: $form['plugin'] = [ Chris@0: '#type' => 'value', Chris@0: '#value' => $this->entity->get('plugin'), Chris@0: ]; Chris@0: $form['type'] = [ Chris@0: '#type' => 'value', Chris@0: '#value' => $this->entity->getType(), Chris@0: ]; Chris@0: Chris@0: if ($this->plugin instanceof PluginFormInterface) { Chris@0: $form += $this->plugin->buildConfigurationForm($form, $form_state); Chris@0: } Chris@0: Chris@0: return parent::form($form, $form_state); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Determines if the action already exists. Chris@0: * Chris@0: * @param string $id Chris@0: * The action ID Chris@0: * Chris@0: * @return bool Chris@0: * TRUE if the action exists, FALSE otherwise. Chris@0: */ Chris@0: public function exists($id) { Chris@0: $action = $this->storage->load($id); Chris@0: return !empty($action); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: protected function actions(array $form, FormStateInterface $form_state) { Chris@0: $actions = parent::actions($form, $form_state); Chris@0: unset($actions['delete']); Chris@0: return $actions; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function validateForm(array &$form, FormStateInterface $form_state) { Chris@0: parent::validateForm($form, $form_state); Chris@0: Chris@0: if ($this->plugin instanceof PluginFormInterface) { Chris@0: $this->plugin->validateConfigurationForm($form, $form_state); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function submitForm(array &$form, FormStateInterface $form_state) { Chris@0: parent::submitForm($form, $form_state); Chris@0: Chris@0: if ($this->plugin instanceof PluginFormInterface) { Chris@0: $this->plugin->submitConfigurationForm($form, $form_state); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function save(array $form, FormStateInterface $form_state) { Chris@0: $this->entity->save(); Chris@0: drupal_set_message($this->t('The action has been successfully saved.')); Chris@0: Chris@0: $form_state->setRedirect('entity.action.collection'); Chris@0: } Chris@0: Chris@0: }