ForwardForm.php in Forward 8
File
src/Plugin/DsField/ForwardForm.php
View source
<?php
namespace Drupal\forward\Plugin\DsField;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\ds\Plugin\DsField\DsFieldBase;
use Drupal\forward\ForwardAccessCheckerInterface;
use Drupal\forward\ForwardFormBuilderInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ForwardForm extends DsFieldBase implements ContainerFactoryPluginInterface {
protected $accessChecker;
protected $formBuilder;
protected $settings;
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;
$settings = $config_factory
->get('forward.settings')
->get();
$settings['forward_interface_type'] = 'form';
$this->settings = $settings;
}
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'));
}
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());
}
public function build() {
$render_array = array();
$config = $this
->getConfiguration();
if (empty($config['build']['#forward_build'])) {
$render_array = $this->formBuilder
->buildForwardEntityForm($this
->entity(), $this->settings);
}
return $render_array;
}
}