class ActionAddFormController

Provides a form controller for action add forms.

Hierarchy

Expanded class hierarchy of ActionAddFormController

File

drupal/core/modules/action/lib/Drupal/action/ActionAddFormController.php, line 19
Contains \Drupal\action\ActionAddFormController.

Namespace

Drupal\action
View source
class ActionAddFormController extends ActionFormControllerBase implements EntityControllerInterface {

  /**
   * The action manager.
   *
   * @var \Drupal\Core\Action\ActionManager
   */
  protected $actionManager;

  /**
   * Constructs a new ActionAddFormController.
   *
   * @param \Drupal\Core\Entity\EntityStorageControllerInterface $storage_controller
   *   The action storage controller.
   * @param \Drupal\Core\Action\ActionManager $action_manager
   *   The action plugin manager.
   */
  public function __construct(EntityStorageControllerInterface $storage_controller, ActionManager $action_manager) {
    parent::__construct($storage_controller);
    $this->actionManager = $action_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) {
    return new static($container
      ->get('plugin.manager.entity')
      ->getStorageController($entity_type), $container
      ->get('plugin.manager.action'));
  }

  /**
   * {@inheritdoc}
   *
   * @param string $action_id
   *   The hashed version of the action ID.
   */
  public function buildForm(array $form, array &$form_state, $action_id = NULL) {

    // In \Drupal\action\Form\ActionAdminManageForm::buildForm() the action
    // are hashed. Here we have to decrypt it to find the desired action ID.
    foreach ($this->actionManager
      ->getDefinitions() as $id => $definition) {
      $key = Crypt::hashBase64($id);
      if ($key === $action_id) {
        $this->entity
          ->setPlugin($id);

        // Derive the label and type from the action definition.
        $this->entity
          ->set('label', $definition['label']);
        $this->entity
          ->set('type', $definition['type']);
        break;
      }
    }
    return parent::buildForm($form, $form_state);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ActionAddFormController::$actionManager protected property The action manager.
ActionAddFormController::buildForm public function Overrides ActionFormControllerBase::buildForm
ActionAddFormController::createInstance public static function Instantiates a new instance of this entity controller. Overrides ActionFormControllerBase::createInstance
ActionAddFormController::__construct public function Constructs a new ActionAddFormController. Overrides ActionFormControllerBase::__construct
ActionFormControllerBase::$plugin protected property The action plugin being configured.
ActionFormControllerBase::$storageController protected property The action storage controller.
ActionFormControllerBase::actions protected function Returns an array of supported actions for the current entity form. Overrides EntityFormController::actions
ActionFormControllerBase::exists public function Determines if the action already exists.
ActionFormControllerBase::form public function Returns the actual form array to be built. Overrides EntityFormController::form
ActionFormControllerBase::save public function Form submission handler for the 'save' action. Overrides EntityFormController::save
ActionFormControllerBase::submit public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::submit(). Overrides EntityFormController::submit
ActionFormControllerBase::validate public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::validate(). Overrides EntityFormController::validate
EntityFormController::$entity protected property The entity being used by this form.
EntityFormController::$operation protected property The name of the current operation.
EntityFormController::actionsElement protected function Returns the action form element for the current entity form.
EntityFormController::buildEntity public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::buildEntity(). Overrides EntityFormControllerInterface::buildEntity 2
EntityFormController::delete public function Form submission handler for the 'delete' action. 12
EntityFormController::getBaseFormID public function Returns a string identifying the base form. Overrides BaseFormIdInterface::getBaseFormID
EntityFormController::getEntity public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::getEntity(). Overrides EntityFormControllerInterface::getEntity
EntityFormController::getFormDisplay public function Returns the form display. Overrides EntityFormControllerInterface::getFormDisplay
EntityFormController::getFormID public function Returns a unique string identifying the form. Overrides FormInterface::getFormID
EntityFormController::getFormLangcode public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::getFormLangcode(). Overrides EntityFormControllerInterface::getFormLangcode
EntityFormController::getOperation public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::getOperation(). Overrides EntityFormControllerInterface::getOperation
EntityFormController::init protected function Initialize the form state and the entity before the first form build. 1
EntityFormController::isDefaultFormLangcode public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::isDefaultFormLangcode(). Overrides EntityFormControllerInterface::isDefaultFormLangcode
EntityFormController::prepareEntity protected function Prepares the entity object before the form is built first. 3
EntityFormController::setEntity public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::setEntity(). Overrides EntityFormControllerInterface::setEntity
EntityFormController::setFormDisplay public function Sets the form display. Overrides EntityFormControllerInterface::setFormDisplay
EntityFormController::setOperation public function Sets the operation for this form.
EntityFormController::submitEntityLanguage protected function Handle possible entity language changes. 1
EntityFormController::submitForm public function Form submission handler. Overrides FormInterface::submitForm
EntityFormController::updateFormLangcode protected function Updates the form language to reflect any change to the entity language.
EntityFormController::validateForm public function Form validation handler. Overrides FormInterface::validateForm