You are here

class ForwardForm in Forward 8

Same name in this branch
  1. 8 src/Form/ForwardForm.php \Drupal\forward\Form\ForwardForm
  2. 8 src/Plugin/DsField/ForwardForm.php \Drupal\forward\Plugin\DsField\ForwardForm
Same name and namespace in other branches
  1. 8.3 src/Plugin/DsField/ForwardForm.php \Drupal\forward\Plugin\DsField\ForwardForm
  2. 8.2 src/Plugin/DsField/ForwardForm.php \Drupal\forward\Plugin\DsField\ForwardForm

Forward form plugin.

Plugin annotation


@DsField(
  id = "forward_form",
  title = @Translation("Forward form"),
  entity_type = "node"
)

Hierarchy

Expanded class hierarchy of ForwardForm

File

src/Plugin/DsField/ForwardForm.php, line 21

Namespace

Drupal\forward\Plugin\DsField
View source
class ForwardForm extends DsFieldBase implements ContainerFactoryPluginInterface {

  /**
   * The access checker service.
   *
   * @var \Drupal\forward\ForwardAccessCheckerInterface
   */
  protected $accessChecker;

  /**
   * The form builder service.
   *
   * @var \Drupal\forward\ForwardFormBuilderInterface
   */
  protected $formBuilder;

  /**
   * The settings used for this plugin instance.
   *
   * @var array
   */
  protected $settings;

  /**
   * Constructs a Display Suite field plugin.
   *
   * @param array $configuration
   * @param string $plugin_id
   * @param mixed $plugin_definition
   * @param \Drupal\forward\ForwardAccessCheckerInterface $access_checker
   * @param \Drupal\forward\ForwardFormBuilderInterface $form_builder
   * @param \Drupal\Core\Config\ConfigFactoryInterface; $configFactory
   */
  public function __construct($configuration, $plugin_id, $plugin_definition, ForwardAccessCheckerInterface $access_checker, ForwardFormBuilderInterface $form_builder, ConfigFactoryInterface $config_factory) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->accessChecker = $access_checker;
    $this->formBuilder = $form_builder;

    // Force the "form" interface
    $settings = $config_factory
      ->get('forward.settings')
      ->get();
    $settings['forward_interface_type'] = 'form';
    $this->settings = $settings;
  }

  /**
   * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
   * @param array $configuration
   * @param string $plugin_id
   * @param mixed $plugin_definition
   * @return static
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('forward.access_checker'), $container
      ->get('forward.form_builder'), $container
      ->get('config.factory'));
  }

  /**
   * {@inheritdoc}
   */
  public function isAllowed() {
    $config = $this
      ->getConfiguration();
    $entity = isset($config['entity']) ? $this
      ->entity() : NULL;
    return $this->accessChecker
      ->isAllowed($this->settings, $entity, $this
      ->viewMode(), $this
      ->getEntityTypeId(), $this
      ->bundle());
  }

  /**
   * {@inheritdoc}
   */
  public function build() {
    $render_array = array();

    // Build the form unless Forward is rendering an email
    $config = $this
      ->getConfiguration();
    if (empty($config['build']['#forward_build'])) {
      $render_array = $this->formBuilder
        ->buildForwardEntityForm($this
        ->entity(), $this->settings);
    }
    return $render_array;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ForwardForm::$accessChecker protected property The access checker service.
ForwardForm::$formBuilder protected property The form builder service.
ForwardForm::$settings protected property The settings used for this plugin instance.
ForwardForm::build public function
ForwardForm::create public static function Overrides ContainerFactoryPluginInterface::create
ForwardForm::isAllowed public function
ForwardForm::__construct public function Constructs a Display Suite field plugin.