diff --git a/modules/webform_access/src/Plugin/Block/WebformAccessGroupEntityBlock.php b/modules/webform_access/src/Plugin/Block/WebformAccessGroupEntityBlock.php index 2ec9c83f..42af7555 100644 --- a/modules/webform_access/src/Plugin/Block/WebformAccessGroupEntityBlock.php +++ b/modules/webform_access/src/Plugin/Block/WebformAccessGroupEntityBlock.php @@ -3,9 +3,7 @@ namespace Drupal\webform_access\Plugin\Block; use Drupal\Core\Block\BlockBase; -use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\Core\Session\AccountInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -33,37 +31,14 @@ class WebformAccessGroupEntityBlock extends BlockBase implements ContainerFactor */ protected $webformAccessGroupStorage; - /** - * Creates a WebformAccessGroupEntityBlock instance. - * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Drupal\Core\Session\AccountInterface $current_user - * The current user. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, AccountInterface $current_user, EntityTypeManagerInterface $entity_type_manager) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->currentUser = $current_user; - $this->webformAccessGroupStorage = $entity_type_manager->getStorage('webform_access_group'); - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('current_user'), - $container->get('entity_type.manager') - ); + $instance = new static($configuration, $plugin_id, $plugin_definition); + $instance->currentUser = $container->get('current_user'); + $instance->webformAccessGroupStorage = $container->get('entity_type.manager'); + return $instance; } /** diff --git a/modules/webform_access/src/WebformAccessGroupListBuilder.php b/modules/webform_access/src/WebformAccessGroupListBuilder.php index 254bca01..44bcbe13 100644 --- a/modules/webform_access/src/WebformAccessGroupListBuilder.php +++ b/modules/webform_access/src/WebformAccessGroupListBuilder.php @@ -4,10 +4,7 @@ namespace Drupal\webform_access; use Drupal\Core\Config\Entity\ConfigEntityListBuilder; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Session\AccountInterface; use Drupal\Core\Url; use Drupal\user\Entity\User; use Drupal\webform\Element\WebformHtmlEditor; @@ -40,34 +37,14 @@ class WebformAccessGroupListBuilder extends ConfigEntityListBuilder { */ protected $entityTypeManager; - /** - * Constructs a new WebformListBuilder object. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type definition. - * @param \Drupal\Core\Entity\EntityStorageInterface $storage - * The entity storage class. - * @param \Drupal\Core\Session\AccountInterface $current_user - * The current user. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - */ - public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, AccountInterface $current_user, EntityTypeManagerInterface $entity_type_manager) { - parent::__construct($entity_type, $storage); - $this->currentUser = $current_user; - $this->entityTypeManager = $entity_type_manager; - } - /** * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $entity_type, - $container->get('entity.manager')->getStorage($entity_type->id()), - $container->get('current_user'), - $container->get('entity_type.manager') - ); + $instance = parent::createInstance($container, $entity_type); + $instance->currentUser = $container->get('current_user'); + $instance->entityTypeManager = $container->get('entity_type.manager'); + return $instance; } /** diff --git a/modules/webform_access/src/WebformAccessGroupStorage.php b/modules/webform_access/src/WebformAccessGroupStorage.php index 91335c75..9f5e38ba 100644 --- a/modules/webform_access/src/WebformAccessGroupStorage.php +++ b/modules/webform_access/src/WebformAccessGroupStorage.php @@ -2,15 +2,9 @@ namespace Drupal\webform_access; -use Drupal\Component\Uuid\UuidInterface; -use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface; -use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\Entity\ConfigEntityStorage; -use Drupal\Core\Database\Connection; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Session\AccountInterface; use Drupal\webform\WebformInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -34,45 +28,14 @@ class WebformAccessGroupStorage extends ConfigEntityStorage implements WebformAc */ protected $entityTypeManager; - /** - * Constructs a WebformAccessGroupStorage object. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type definition. - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The config factory service. - * @param \Drupal\Component\Uuid\UuidInterface $uuid_service - * The UUID service. - * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager - * The language manager. - * @param \Drupal\Core\Database\Connection $database - * The database connection to be used. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - * @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface $memory_cache - * The memory cache. - * - * @todo Webform 8.x-6.x: Move $memory_cache right after $language_manager. - */ - public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, Connection $database, EntityTypeManagerInterface $entity_type_manager, MemoryCacheInterface $memory_cache = NULL) { - parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager, $memory_cache); - $this->database = $database; - $this->entityTypeManager = $entity_type_manager; - } - /** * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $entity_type, - $container->get('config.factory'), - $container->get('uuid'), - $container->get('language_manager'), - $container->get('database'), - $container->get('entity_type.manager'), - $container->get('entity.memory_cache') - ); + $instance = parent::createInstance($container, $entity_type); + $instance->database = $container->get('database'); + $instance->entityTypeManager = $container->get('entity_type.manager'); + return $instance; } /** diff --git a/modules/webform_access/src/WebformAccessTypeListBuilder.php b/modules/webform_access/src/WebformAccessTypeListBuilder.php index 03d58c69..5f451528 100644 --- a/modules/webform_access/src/WebformAccessTypeListBuilder.php +++ b/modules/webform_access/src/WebformAccessTypeListBuilder.php @@ -4,7 +4,6 @@ namespace Drupal\webform_access; use Drupal\Core\Config\Entity\ConfigEntityListBuilder; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\webform\Utility\WebformDialogHelper; use Drupal\webform_access\Entity\WebformAccessGroup; @@ -29,23 +28,13 @@ class WebformAccessTypeListBuilder extends ConfigEntityListBuilder { */ protected $accessGroupStorage; - /** - * {@inheritdoc} - */ - public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, WebformAccessGroupStorageInterface $access_group_storage) { - parent::__construct($entity_type, $storage); - $this->accessGroupStorage = $access_group_storage; - } - /** * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $entity_type, - $container->get('entity.manager')->getStorage($entity_type->id()), - $container->get('entity.manager')->getStorage('webform_access_group') - ); + $instance = parent::createInstance($container, $entity_type); + $instance->accessGroupStorage = $container->get('entity.manager')->getStorage('webform_access_group'); + return $instance; } /** diff --git a/modules/webform_entity_print/src/Plugin/WebformExporter/WebformEntityPrintWebformExporter.php b/modules/webform_entity_print/src/Plugin/WebformExporter/WebformEntityPrintWebformExporter.php index 8b9b3378..f4d1a49c 100644 --- a/modules/webform_entity_print/src/Plugin/WebformExporter/WebformEntityPrintWebformExporter.php +++ b/modules/webform_entity_print/src/Plugin/WebformExporter/WebformEntityPrintWebformExporter.php @@ -3,19 +3,10 @@ namespace Drupal\webform_entity_print\Plugin\WebformExporter; use Drupal\Core\Archiver\ArchiveTar; -use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\entity_print\Plugin\ExportTypeManagerInterface; -use Drupal\entity_print\PrintBuilderInterface; -use Drupal\entity_print\Plugin\EntityPrintPluginManagerInterface; -use Drupal\webform\Plugin\WebformElementManagerInterface; use Drupal\webform\Plugin\WebformExporter\DocumentBaseWebformExporter; use Drupal\webform\WebformSubmissionInterface; -use Drupal\webform\WebformTokenManagerInterface; -use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpFoundation\RequestStack; /** * Defines a Webform Entity Print PDF exporter. @@ -57,35 +48,16 @@ class WebformEntityPrintWebformExporter extends DocumentBaseWebformExporter { */ protected $printBuilder; - /** - * Constructs a WebformEntityPrintBaseWebformExporter object. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerInterface $logger, ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, WebformElementManagerInterface $element_manager, WebformTokenManagerInterface $token_manager, RequestStack $request_stack, EntityPrintPluginManagerInterface $print_engine_manager, ExportTypeManagerInterface $export_type_manager, PrintBuilderInterface $print_builder) { - parent::__construct($configuration, $plugin_id, $plugin_definition, $logger, $config_factory, $entity_type_manager, $element_manager, $token_manager); - $this->request = $request_stack->getCurrentRequest(); - $this->printEngineManager = $print_engine_manager; - $this->exportTypeManager = $export_type_manager; - $this->printBuilder = $print_builder; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('logger.factory')->get('webform'), - $container->get('config.factory'), - $container->get('entity_type.manager'), - $container->get('plugin.manager.webform.element'), - $container->get('webform.token_manager'), - $container->get('request_stack'), - $container->get('plugin.manager.entity_print.print_engine'), - $container->get('plugin.manager.entity_print.export_type'), - $container->get('entity_print.print_builder') - ); + $instance = parent::create($container, $configuration, $plugin_id, $plugin_definition); + $instance->request = $container->get('request_stack')->getCurrentRequest(); + $instance->printEngineManager = $container->get('plugin.manager.entity_print.print_engine'); + $instance->exportTypeManager = $container->get('plugin.manager.entity_print.export_type'); + $instance->printBuilder = $container->get('entity_print.print_builder'); + return $instance; } /** diff --git a/modules/webform_example_handler/src/Plugin/WebformHandler/ExampleWebformHandler.php b/modules/webform_example_handler/src/Plugin/WebformHandler/ExampleWebformHandler.php index 8adea8fd..43d4e00e 100644 --- a/modules/webform_example_handler/src/Plugin/WebformHandler/ExampleWebformHandler.php +++ b/modules/webform_example_handler/src/Plugin/WebformHandler/ExampleWebformHandler.php @@ -3,16 +3,11 @@ namespace Drupal\webform_example_handler\Plugin\WebformHandler; use Drupal\Component\Utility\Xss; -use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Render\Markup; use Drupal\webform\Plugin\WebformHandlerBase; use Drupal\webform\WebformInterface; -use Drupal\webform\WebformSubmissionConditionsValidatorInterface; use Drupal\webform\WebformSubmissionInterface; -use Drupal\webform\WebformTokenManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -37,28 +32,13 @@ class ExampleWebformHandler extends WebformHandlerBase { */ protected $tokenManager; - /** - * {@inheritdoc} - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerChannelFactoryInterface $logger_factory, ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, WebformSubmissionConditionsValidatorInterface $conditions_validator, WebformTokenManagerInterface $token_manager) { - parent::__construct($configuration, $plugin_id, $plugin_definition, $logger_factory, $config_factory, $entity_type_manager, $conditions_validator); - $this->tokenManager = $token_manager; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('logger.factory'), - $container->get('config.factory'), - $container->get('entity_type.manager'), - $container->get('webform_submission.conditions_validator'), - $container->get('webform.token_manager') - ); + $instance = parent::create($container, $configuration, $plugin_id, $plugin_definition); + $instance->tokenManager = $container->get('webform.token_manager'); + return $instance; } /** diff --git a/modules/webform_image_select/src/WebformImageSelectImagesListBuilder.php b/modules/webform_image_select/src/WebformImageSelectImagesListBuilder.php index a43dc187..21362554 100644 --- a/modules/webform_image_select/src/WebformImageSelectImagesListBuilder.php +++ b/modules/webform_image_select/src/WebformImageSelectImagesListBuilder.php @@ -4,14 +4,12 @@ namespace Drupal\webform_image_select; use Drupal\Core\Config\Entity\ConfigEntityListBuilder; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Url; use Drupal\webform\Utility\WebformDialogHelper; use Drupal\webform_image_select\Entity\WebformImageSelectImages; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpFoundation\RequestStack; /** * Defines a class to build a listing of webform image select images entities. @@ -20,6 +18,13 @@ use Symfony\Component\HttpFoundation\RequestStack; */ class WebformImageSelectImagesListBuilder extends ConfigEntityListBuilder { + /** + * The current request. + * + * @var \Symfony\Component\HttpFoundation\Request + */ + protected $request; + /** * Search keys. * @@ -35,32 +40,24 @@ class WebformImageSelectImagesListBuilder extends ConfigEntityListBuilder { protected $category; /** - * Constructs a new WebformImageSelectImagesListBuilder object. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type definition. - * @param \Drupal\Core\Entity\EntityStorageInterface $storage - * The entity storage class. - * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack - * The request stack. + * {@inheritdoc} */ - public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, RequestStack $request_stack) { - parent::__construct($entity_type, $storage); - $this->request = $request_stack->getCurrentRequest(); + public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { + /** @var \Drupal\webform_image_select\WebformImageSelectImagesListBuilder $instance */ + $instance = parent::createInstance($container, $entity_type); - $this->keys = $this->request->query->get('search'); - $this->category = $this->request->query->get('category'); + $instance->request = $container->get('request_stack')->getCurrentRequest(); + + $instance->initialize(); + return $instance; } /** - * {@inheritdoc} + * Initialize WebformImageSelectImagesListBuilder object. */ - public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $entity_type, - $container->get('entity.manager')->getStorage($entity_type->id()), - $container->get('request_stack') - ); + protected function initialize() { + $this->keys = $this->request->query->get('search'); + $this->category = $this->request->query->get('category'); } /** diff --git a/modules/webform_node/src/Controller/WebformNodeReferencesListController.php b/modules/webform_node/src/Controller/WebformNodeReferencesListController.php index aa0ab77a..872df14c 100644 --- a/modules/webform_node/src/Controller/WebformNodeReferencesListController.php +++ b/modules/webform_node/src/Controller/WebformNodeReferencesListController.php @@ -2,17 +2,11 @@ namespace Drupal\webform_node\Controller; -use Drupal\Core\Datetime\DateFormatterInterface; -use Drupal\Core\Config\Entity\ConfigEntityStorageInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityListBuilder; -use Drupal\Core\Entity\EntityStorageInterface; -use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Url; -use Drupal\webform\WebformEntityReferenceManagerInterface; use Drupal\webform\WebformInterface; -use Drupal\webform\WebformSubmissionStorageInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -101,32 +95,24 @@ class WebformNodeReferencesListController extends EntityListBuilder implements C } /** - * Constructs a new WebformNodeReferencesListController object. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type definition. - * @param \Drupal\Core\Entity\EntityStorageInterface $storage - * The entity storage class. - * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter - * The date formatter service. - * @param \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $node_type_storage - * The node type storage class. - * @param \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $field_config_storage - * The field config storage class. - * @param \Drupal\webform\WebformSubmissionStorageInterface $webform_submission_storage - * The webform submission storage class. - * @param \Drupal\webform\WebformEntityReferenceManagerInterface $webform_entity_reference_manager - * The webform entity reference manager. + * {@inheritdoc} */ - public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, DateFormatterInterface $date_formatter, ConfigEntityStorageInterface $node_type_storage, ConfigEntityStorageInterface $field_config_storage, WebformSubmissionStorageInterface $webform_submission_storage, WebformEntityReferenceManagerInterface $webform_entity_reference_manager) { - parent::__construct($entity_type, $storage); - - $this->dateFormatter = $date_formatter; - $this->nodeTypeStorage = $node_type_storage; - $this->fieldConfigStorage = $field_config_storage; - $this->submissionStorage = $webform_submission_storage; - $this->webformEntityReferenceManager = $webform_entity_reference_manager; + public static function create(ContainerInterface $container) { + /** @var web/core/lib/Drupal/Core/Entity/EntityTypeManagerInterface.php:12 $entity_type_manager */ + $entity_type_manager = $container->get('entity_type.manager'); + $instance = static::createInstance($container, $entity_type_manager->getDefinition('node')); + + $instance->dateFormatter = $container->get('date.formatter'); + $instance->nodeTypeStorage = $entity_type_manager->getStorage('node_type'); + $instance->fieldConfigStorage = $entity_type_manager->getStorage('field_config'); + $instance->submissionStorage = $entity_type_manager->getStorage('webform_submission'); + $instance->webformEntityReferenceManager = $container->get('webform.entity_reference_manager'); + + $instance->initialize(); + return $instance; + } + protected function initialize() { $this->nodeTypes = []; $this->fieldNames = []; @@ -143,21 +129,7 @@ class WebformNodeReferencesListController extends EntityListBuilder implements C $this->fieldNames[$field_name] = $field_name; } } - } - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('entity_type.manager')->getDefinition('node'), - $container->get('entity_type.manager')->getStorage('node'), - $container->get('date.formatter'), - $container->get('entity_type.manager')->getStorage('node_type'), - $container->get('entity_type.manager')->getStorage('field_config'), - $container->get('entity_type.manager')->getStorage('webform_submission'), - $container->get('webform.entity_reference_manager') - ); } /** diff --git a/src/Controller/WebformSubmissionViewController.php b/src/Controller/WebformSubmissionViewController.php index baeaf69e..f667a7f5 100644 --- a/src/Controller/WebformSubmissionViewController.php +++ b/src/Controller/WebformSubmissionViewController.php @@ -4,11 +4,7 @@ namespace Drupal\webform\Controller; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Controller\EntityViewController; -use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\Render\RendererInterface; -use Drupal\Core\Session\AccountInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\webform\WebformRequestInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -32,34 +28,14 @@ class WebformSubmissionViewController extends EntityViewController { */ protected $requestHandler; - /** - * Creates an WebformSubmissionViewController object. - * - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager. - * @param \Drupal\Core\Render\RendererInterface $renderer - * The renderer service. - * @param \Drupal\Core\Session\AccountInterface $current_user - * The current user. - * @param \Drupal\webform\WebformRequestInterface $webform_request - * The webform request handler. - */ - public function __construct(EntityManagerInterface $entity_manager, RendererInterface $renderer, AccountInterface $current_user, WebformRequestInterface $webform_request) { - parent::__construct($entity_manager, $renderer); - $this->currentUser = $current_user; - $this->requestHandler = $webform_request; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static( - $container->get('entity.manager'), - $container->get('renderer'), - $container->get('current_user'), - $container->get('webform.request') - ); + $instance = parent::create($container); + $instance->currentUser = $container->get('current_user'); + $instance->requestHandler = $container->get('webform.request'); + return $instance; } /** diff --git a/src/Form/AdminConfig/WebformAdminConfigAdvancedForm.php b/src/Form/AdminConfig/WebformAdminConfigAdvancedForm.php index 0c721cfb..f8d0269f 100644 --- a/src/Form/AdminConfig/WebformAdminConfigAdvancedForm.php +++ b/src/Form/AdminConfig/WebformAdminConfigAdvancedForm.php @@ -2,13 +2,8 @@ namespace Drupal\webform\Form\AdminConfig; -use Drupal\Core\Cache\CacheBackendInterface; -use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Routing\RouteBuilderInterface; use Drupal\Core\Url; -use Drupal\webform\Commands\WebformCliService; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -51,39 +46,16 @@ class WebformAdminConfigAdvancedForm extends WebformAdminConfigBaseForm { return 'webform_admin_config_advanced_form'; } - /** - * Constructs a WebformAdminConfigAdvancedForm object. - * - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The factory for configuration objects. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler. - * @param \Drupal\Core\Cache\CacheBackendInterface $render_cache - * The render cache service. - * @param \Drupal\Core\Routing\RouteBuilderInterface $router_builder - * The router builder service. - * @param \Drupal\webform\Commands\WebformCliService $cli_service - * The (drush) command-line service. - */ - public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, CacheBackendInterface $render_cache, RouteBuilderInterface $router_builder, WebformCliService $cli_service) { - parent::__construct($config_factory); - $this->renderCache = $render_cache; - $this->moduleHandler = $module_handler; - $this->routerBuilder = $router_builder; - $this->cliService = $cli_service; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static( - $container->get('config.factory'), - $container->get('module_handler'), - $container->get('cache.render'), - $container->get('router.builder'), - $container->get('webform.cli_service') - ); + $instance = parent::create($container); + $instance->renderCache = $container->get('cache.render'); + $instance->moduleHandler = $container->get('module_handler'); + $instance->routerBuilder = $container->get('router.builder'); + $instance->cliService = $container->get('webform.cli_service'); + return $instance; } /** diff --git a/src/Form/AdminConfig/WebformAdminConfigElementsForm.php b/src/Form/AdminConfig/WebformAdminConfigElementsForm.php index fe66f887..e65c2b6d 100644 --- a/src/Form/AdminConfig/WebformAdminConfigElementsForm.php +++ b/src/Form/AdminConfig/WebformAdminConfigElementsForm.php @@ -4,16 +4,11 @@ namespace Drupal\webform\Form\AdminConfig; use Drupal\Component\Utility\Bytes; use Drupal\Component\Utility\Xss; -use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\file\Plugin\Field\FieldType\FileItem; use Drupal\webform\Element\WebformMessage; use Drupal\webform\Utility\WebformArrayHelper; use Drupal\webform\Utility\WebformOptionsHelper; -use Drupal\webform\Plugin\WebformElementManagerInterface; -use Drupal\webform\WebformLibrariesManagerInterface; -use Drupal\webform\WebformTokenManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -56,39 +51,16 @@ class WebformAdminConfigElementsForm extends WebformAdminConfigBaseForm { return 'webform_admin_config_elements_form'; } - /** - * Constructs a WebformAdminConfigElementsForm object. - * - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The factory for configuration objects. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler. - * @param \Drupal\webform\WebformTokenManagerInterface $token_manager - * The webform token manager. - * @param \Drupal\webform\Plugin\WebformElementManagerInterface $element_manager - * The webform element manager. - * @param \Drupal\webform\WebformLibrariesManagerInterface $libraries_manager - * The webform libraries manager. - */ - public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, WebformTokenManagerInterface $token_manager, WebformElementManagerInterface $element_manager, WebformLibrariesManagerInterface $libraries_manager) { - parent::__construct($config_factory); - $this->moduleHandler = $module_handler; - $this->tokenManager = $token_manager; - $this->elementManager = $element_manager; - $this->librariesManager = $libraries_manager; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static( - $container->get('config.factory'), - $container->get('module_handler'), - $container->get('webform.token_manager'), - $container->get('plugin.manager.webform.element'), - $container->get('webform.libraries_manager') - ); + $instance = parent::create($container); + $instance->moduleHandler = $container->get('module_handler'); + $instance->tokenManager = $container->get('webform.token_manager'); + $instance->elementManager = $container->get('plugin.manager.webform.element'); + $instance->librariesManager = $container->get('webform.libraries_manager'); + return $instance; } /** diff --git a/src/Form/AdminConfig/WebformAdminConfigExportersForm.php b/src/Form/AdminConfig/WebformAdminConfigExportersForm.php index ac8c6267..78149cd1 100644 --- a/src/Form/AdminConfig/WebformAdminConfigExportersForm.php +++ b/src/Form/AdminConfig/WebformAdminConfigExportersForm.php @@ -2,12 +2,8 @@ namespace Drupal\webform\Form\AdminConfig; -use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Form\FormState; -use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\webform\Plugin\WebformExporterManagerInterface; -use Drupal\webform\WebformSubmissionExporterInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -43,35 +39,15 @@ class WebformAdminConfigExportersForm extends WebformAdminConfigBaseForm { return 'webform_admin_config_exporters_form'; } - /** - * Constructs a WebformAdminConfigExportersForm object. - * - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The factory for configuration objects. - * @param \Drupal\Core\File\FileSystemInterface $file_system - * The file system service. - * @param \Drupal\webform\Plugin\WebformExporterManagerInterface $exporter_manager - * The webform exporter manager. - * @param \Drupal\webform\WebformSubmissionExporterInterface $submission_exporter - * The webform submission exporter. - */ - public function __construct(ConfigFactoryInterface $config_factory, FileSystemInterface $file_system, WebformExporterManagerInterface $exporter_manager, WebformSubmissionExporterInterface $submission_exporter) { - parent::__construct($config_factory); - $this->fileSystem = $file_system; - $this->exporterManager = $exporter_manager; - $this->submissionExporter = $submission_exporter; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static( - $container->get('config.factory'), - $container->get('file_system'), - $container->get('plugin.manager.webform.exporter'), - $container->get('webform_submission.exporter') - ); + $instance = parent::create($container); + $instance->fileSystem = $container->get('file_system'); + $instance->exporterManager = $container->get('plugin.manager.webform.exporter'); + $instance->submissionExporter = $container->get('webform_submission.exporter'); + return $instance; } /** diff --git a/src/Form/AdminConfig/WebformAdminConfigFormsForm.php b/src/Form/AdminConfig/WebformAdminConfigFormsForm.php index 4c654506..af4c5d5f 100644 --- a/src/Form/AdminConfig/WebformAdminConfigFormsForm.php +++ b/src/Form/AdminConfig/WebformAdminConfigFormsForm.php @@ -2,8 +2,6 @@ namespace Drupal\webform\Form\AdminConfig; -use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; use Drupal\Core\Url; @@ -11,10 +9,7 @@ use Drupal\filter\Entity\FilterFormat; use Drupal\webform\Element\WebformMessage; use Drupal\webform\Entity\Webform; use Drupal\webform\Utility\WebformArrayHelper; -use Drupal\webform\WebformAddonsManagerInterface; use Drupal\webform\WebformInterface; -use Drupal\webform\WebformTokenManagerInterface; -use Drupal\webform\WebformThirdPartySettingsManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -57,39 +52,16 @@ class WebformAdminConfigFormsForm extends WebformAdminConfigBaseForm { return 'webform_admin_config_forms_form'; } - /** - * Constructs a WebformAdminConfigFormsForm object. - * - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The factory for configuration objects. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler. - * @param \Drupal\webform\WebformTokenManagerInterface $token_manager - * The webform token manager. - * @param \Drupal\webform\WebformThirdPartySettingsManagerInterface $third_party_settings_manager - * The webform third party settings manager. - * @param \Drupal\webform\WebformAddonsManagerInterface $addons_manager - * The webform add-ons manager. - */ - public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, WebformTokenManagerInterface $token_manager, WebformThirdPartySettingsManagerInterface $third_party_settings_manager, WebformAddonsManagerInterface $addons_manager) { - parent::__construct($config_factory); - $this->moduleHandler = $module_handler; - $this->tokenManager = $token_manager; - $this->thirdPartySettingsManager = $third_party_settings_manager; - $this->addonsManager = $addons_manager; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static( - $container->get('config.factory'), - $container->get('module_handler'), - $container->get('webform.token_manager'), - $container->get('webform.third_party_settings_manager'), - $container->get('webform.addons_manager') - ); + $instance = parent::create($container); + $instance->moduleHandler = $container->get('module_handler'); + $instance->tokenManager = $container->get('webform.token_manager'); + $instance->thirdPartySettingsManager = $container->get('webform.third_party_settings_manager'); + $instance->addonsManager = $container->get('webform.addons_manager'); + return $instance; } /** diff --git a/src/Form/AdminConfig/WebformAdminConfigHandlersForm.php b/src/Form/AdminConfig/WebformAdminConfigHandlersForm.php index 6e3a51a1..dc21239e 100644 --- a/src/Form/AdminConfig/WebformAdminConfigHandlersForm.php +++ b/src/Form/AdminConfig/WebformAdminConfigHandlersForm.php @@ -2,11 +2,7 @@ namespace Drupal\webform\Form\AdminConfig; -use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\webform\Plugin\WebformHandlerManagerInterface; -use Drupal\webform\WebformTokenManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -42,35 +38,15 @@ class WebformAdminConfigHandlersForm extends WebformAdminConfigBaseForm { return 'webform_admin_config_handlers_form'; } - /** - * Constructs a WebformAdminConfigHandlersForm object. - * - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The factory for configuration objects. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler. - * @param \Drupal\webform\WebformTokenManagerInterface $token_manager - * The webform token manager. - * @param \Drupal\webform\Plugin\WebformHandlerManagerInterface $handler_manager - * The webform handler manager. - */ - public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, WebformTokenManagerInterface $token_manager, WebformHandlerManagerInterface $handler_manager) { - parent::__construct($config_factory); - $this->moduleHandler = $module_handler; - $this->tokenManager = $token_manager; - $this->handlerManager = $handler_manager; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static( - $container->get('config.factory'), - $container->get('module_handler'), - $container->get('webform.token_manager'), - $container->get('plugin.manager.webform.handler') - ); + $instance = parent::create($container); + $instance->moduleHandler = $container->get('module_handler'); + $instance->tokenManager = $container->get('webform.token_manager'); + $instance->handlerManager = $container->get('plugin.manager.webform.handler'); + return $instance; } /** diff --git a/src/Form/AdminConfig/WebformAdminConfigLibrariesForm.php b/src/Form/AdminConfig/WebformAdminConfigLibrariesForm.php index e2b6a6b6..bb1076f7 100644 --- a/src/Form/AdminConfig/WebformAdminConfigLibrariesForm.php +++ b/src/Form/AdminConfig/WebformAdminConfigLibrariesForm.php @@ -2,12 +2,10 @@ namespace Drupal\webform\Form\AdminConfig; -use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; use Drupal\webform\Element\WebformMessage; use Drupal\webform\Plugin\WebformElement\TableSelect; -use Drupal\webform\WebformLibrariesManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -36,27 +34,13 @@ class WebformAdminConfigLibrariesForm extends WebformAdminConfigBaseForm { return 'webform_admin_config_libraries_form'; } - /** - * Constructs a WebformAdminConfigLibrariesForm object. - * - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The factory for configuration objects. - * @param \Drupal\webform\WebformLibrariesManagerInterface $libraries_manager - * The webform libraries manager. - */ - public function __construct(ConfigFactoryInterface $config_factory, WebformLibrariesManagerInterface $libraries_manager) { - parent::__construct($config_factory); - $this->librariesManager = $libraries_manager; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static( - $container->get('config.factory'), - $container->get('webform.libraries_manager') - ); + $instance = parent::create($container); + $instance->librariesManager = $container->get('webform.libraries_manager'); + return $instance; } /** diff --git a/src/Form/AdminConfig/WebformAdminConfigSubmissionsForm.php b/src/Form/AdminConfig/WebformAdminConfigSubmissionsForm.php index 45d15aa9..b8414766 100644 --- a/src/Form/AdminConfig/WebformAdminConfigSubmissionsForm.php +++ b/src/Form/AdminConfig/WebformAdminConfigSubmissionsForm.php @@ -2,11 +2,8 @@ namespace Drupal\webform\Form\AdminConfig; -use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\webform\Element\WebformMessage; -use Drupal\webform\WebformTokenManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -35,31 +32,14 @@ class WebformAdminConfigSubmissionsForm extends WebformAdminConfigBaseForm { return 'webform_admin_config_submissions_form'; } - /** - * Constructs a WebformAdminConfigSubmissionsForm object. - * - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The factory for configuration objects. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler. - * @param \Drupal\webform\WebformTokenManagerInterface $token_manager - * The webform token manager. - */ - public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, WebformTokenManagerInterface $token_manager) { - parent::__construct($config_factory); - $this->moduleHandler = $module_handler; - $this->tokenManager = $token_manager; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static( - $container->get('config.factory'), - $container->get('module_handler'), - $container->get('webform.token_manager') - ); + $instance = parent::create($container); + $instance->moduleHandler = $container->get('module_handler'); + $instance->tokenManager = $container->get('webform.token_manager'); + return $instance; } /** diff --git a/src/Form/WebformHandlerAddForm.php b/src/Form/WebformHandlerAddForm.php index a59c8093..fcc20f47 100644 --- a/src/Form/WebformHandlerAddForm.php +++ b/src/Form/WebformHandlerAddForm.php @@ -2,12 +2,8 @@ namespace Drupal\webform\Form; -use Drupal\Component\Transliteration\TransliterationInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Language\LanguageManagerInterface; -use Drupal\webform\Plugin\WebformHandlerManagerInterface; use Drupal\webform\WebformInterface; -use Drupal\webform\WebformTokenManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; @@ -23,33 +19,13 @@ class WebformHandlerAddForm extends WebformHandlerFormBase { */ protected $webformHandlerManager; - /** - * Constructs a WebformHandlerAddForm. - * - * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager - * The language manager. - * @param \Drupal\Component\Transliteration\TransliterationInterface $transliteration - * The transliteration helper. - * @param \Drupal\webform\WebformTokenManagerInterface $token_manager - * The webform token manager. - * @param \Drupal\webform\Plugin\WebformHandlerManagerInterface $webform_handler - * The webform handler manager. - */ - public function __construct(LanguageManagerInterface $language_manager, TransliterationInterface $transliteration, WebformTokenManagerInterface $token_manager, WebformHandlerManagerInterface $webform_handler) { - parent::__construct($language_manager, $transliteration, $token_manager); - $this->webformHandlerManager = $webform_handler; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static( - $container->get('language_manager'), - $container->get('transliteration'), - $container->get('webform.token_manager'), - $container->get('plugin.manager.webform.handler') - ); + $instance = parent::create($container); + $instance->webformHandlerManager = $container->get('plugin.manager.webform.handler'); + return $instance; } /** diff --git a/src/Form/WebformSubmissionDeleteForm.php b/src/Form/WebformSubmissionDeleteForm.php index 86d12082..5074b9d1 100644 --- a/src/Form/WebformSubmissionDeleteForm.php +++ b/src/Form/WebformSubmissionDeleteForm.php @@ -3,9 +3,7 @@ namespace Drupal\webform\Form; use Drupal\Core\Entity\ContentEntityDeleteForm; -use Drupal\Core\Entity\EntityRepositoryInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\webform\WebformRequestInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -43,27 +41,13 @@ class WebformSubmissionDeleteForm extends ContentEntityDeleteForm implements Web */ protected $requestHandler; - /** - * Constructs a WebformSubmissionDeleteForm object. - * - * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository - * The entity repository. - * @param \Drupal\webform\WebformRequestInterface $request_handler - * The webform request handler. - */ - public function __construct(EntityRepositoryInterface $entity_repository, WebformRequestInterface $request_handler) { - parent::__construct($entity_repository); - $this->requestHandler = $request_handler; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static( - $container->get('entity.repository'), - $container->get('webform.request') - ); + $instance = parent::create($container); + $instance->requestHandler = $container->get('webform.request'); + return $instance; } /** diff --git a/src/Plugin/Action/DeleteWebformSubmission.php b/src/Plugin/Action/DeleteWebformSubmission.php index 682839ad..0ed730d1 100644 --- a/src/Plugin/Action/DeleteWebformSubmission.php +++ b/src/Plugin/Action/DeleteWebformSubmission.php @@ -5,7 +5,6 @@ namespace Drupal\webform\Plugin\Action; use Drupal\Core\Action\ActionBase; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Session\AccountInterface; -use Drupal\Core\TempStore\PrivateTempStoreFactory; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -34,38 +33,14 @@ class DeleteWebformSubmission extends ActionBase implements ContainerFactoryPlug */ protected $currentUser; - /** - * Constructs a DeleteWebformSubmission object. - * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin ID for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory - * The tempstore factory. - * @param \Drupal\Core\Session\AccountInterface $current_user - * The current user. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, PrivateTempStoreFactory $temp_store_factory, AccountInterface $current_user) { - $this->currentUser = $current_user; - $this->tempStoreFactory = $temp_store_factory; - - parent::__construct($configuration, $plugin_id, $plugin_definition); - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('tempstore.private'), - $container->get('current_user') - ); + $instance = new static($configuration, $plugin_id, $plugin_definition); + $instance->currentUser = $container->get('current_user'); + $instance->tempStoreFactory = $container->get('tempstore.private'); + return $instance; } /** diff --git a/src/Plugin/Block/WebformBlock.php b/src/Plugin/Block/WebformBlock.php index d81b3ddd..a57a20b1 100644 --- a/src/Plugin/Block/WebformBlock.php +++ b/src/Plugin/Block/WebformBlock.php @@ -4,15 +4,12 @@ namespace Drupal\webform\Plugin\Block; use Drupal\Core\Access\AccessResult; use Drupal\Core\Block\BlockBase; -use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\EventSubscriber\MainContentViewSubscriber; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Session\AccountInterface; use Drupal\webform\WebformInterface; -use Drupal\webform\WebformTokenManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpFoundation\RequestStack; /** * Provides a 'Webform' block. @@ -46,41 +43,15 @@ class WebformBlock extends BlockBase implements ContainerFactoryPluginInterface */ protected $tokenManager; - /** - * Creates a WebformBlock instance. - * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack - * The request stack. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - * @param \Drupal\webform\WebformTokenManagerInterface $token_manager - * The webform token manager. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, RequestStack $request_stack, EntityTypeManagerInterface $entity_type_manager, WebformTokenManagerInterface $token_manager) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->requestStack = $request_stack; - $this->entityTypeManager = $entity_type_manager; - $this->tokenManager = $token_manager; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('request_stack'), - $container->get('entity_type.manager'), - $container->get('webform.token_manager') - ); + $instance = new static($configuration, $plugin_id, $plugin_definition); + $instance->requestStack = $container->get('request_stack'); + $instance->entityTypeManager = $container->get('entity_type.manager'); + $instance->tokenManager = $container->get('webform.token_manager'); + return $instance; } /** diff --git a/src/Plugin/Block/WebformSubmissionLimitBlock.php b/src/Plugin/Block/WebformSubmissionLimitBlock.php index a1f3d15e..08aa166e 100644 --- a/src/Plugin/Block/WebformSubmissionLimitBlock.php +++ b/src/Plugin/Block/WebformSubmissionLimitBlock.php @@ -5,15 +5,12 @@ namespace Drupal\webform\Plugin\Block; use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Access\AccessResult; use Drupal\Core\Block\BlockBase; -use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Session\AccountInterface; use Drupal\webform\Element\WebformHtmlEditor; use Drupal\webform\Entity\Webform; use Drupal\webform\Utility\WebformDateHelper; -use Drupal\webform\WebformRequestInterface; -use Drupal\webform\WebformTokenManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -55,45 +52,16 @@ class WebformSubmissionLimitBlock extends BlockBase implements ContainerFactoryP */ protected $tokenManager; - /** - * Creates a WebformSubmissionLimitBlock instance. - * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Drupal\Core\Session\AccountInterface $account - * The current user. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - * @param \Drupal\webform\WebformRequestInterface $request_handler - * The webform request handler. - * @param \Drupal\webform\WebformTokenManagerInterface $token_manager - * The webform token manager. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, AccountInterface $account, EntityTypeManagerInterface $entity_type_manager, WebformRequestInterface $request_handler, WebformTokenManagerInterface $token_manager) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->currentUser = $account; - $this->entityTypeManager = $entity_type_manager; - $this->requestHandler = $request_handler; - $this->tokenManager = $token_manager; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('current_user'), - $container->get('entity_type.manager'), - $container->get('webform.request'), - $container->get('webform.token_manager') - ); + $instance = new static($configuration, $plugin_id, $plugin_definition); + $instance->currentUser = $container->get('current_user'); + $instance->entityTypeManager = $container->get('entity_type.manager'); + $instance->requestHandler = $container->get('webform.request'); + $instance->tokenManager = $container->get('webform.token_manager'); + return $instance; } /** diff --git a/src/Plugin/Condition/Webform.php b/src/Plugin/Condition/Webform.php index 62b1514b..42e0ff5e 100644 --- a/src/Plugin/Condition/Webform.php +++ b/src/Plugin/Condition/Webform.php @@ -3,11 +3,9 @@ namespace Drupal\webform\Plugin\Condition; use Drupal\Core\Condition\ConditionPluginBase; -use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\webform\Utility\WebformElementHelper; -use Drupal\webform\WebformEntityReferenceManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -39,40 +37,14 @@ class Webform extends ConditionPluginBase implements ContainerFactoryPluginInter */ protected $webformEntityReferenceManager; - /** - * Creates a new Webform instance. - * - * @param array $configuration - * The plugin configuration, i.e. an array with configuration values keyed - * by configuration option name. The special key 'context' may be used to - * initialize the defined contexts by setting it to an array of context - * values keyed by context names. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage - * The entity storage. - * @param \Drupal\webform\WebformEntityReferenceManagerInterface $webform_entity_reference_manager - * The webform entity reference manager. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityStorageInterface $entity_storage, WebformEntityReferenceManagerInterface $webform_entity_reference_manager) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->entityStorage = $entity_storage; - $this->webformEntityReferenceManager = $webform_entity_reference_manager; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('entity_type.manager')->getStorage('webform'), - $container->get('webform.entity_reference_manager') - ); + $instance = new static($configuration, $plugin_id, $plugin_definition); + $instance->entityStorage = $container->get('entity_type.manager')->getStorage('webform'); + $instance->webformEntityReferenceManager = $container->get('webform.entity_reference_manager'); + return $instance; } /** diff --git a/src/Plugin/DevelGenerate/WebformSubmissionDevelGenerate.php b/src/Plugin/DevelGenerate/WebformSubmissionDevelGenerate.php index 53039613..3cc0dc41 100644 --- a/src/Plugin/DevelGenerate/WebformSubmissionDevelGenerate.php +++ b/src/Plugin/DevelGenerate/WebformSubmissionDevelGenerate.php @@ -2,18 +2,12 @@ namespace Drupal\webform\Plugin\DevelGenerate; -use Drupal\Core\Database\Connection; -use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Serialization\Yaml; use Drupal\devel_generate\DevelGenerateBase; use Drupal\webform\Utility\WebformArrayHelper; -use Drupal\webform\WebformEntityReferenceManagerInterface; -use Drupal\webform\WebformSubmissionGenerateInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpFoundation\RequestStack; /** * Provides a WebformSubmissionDevelGenerate plugin. @@ -97,56 +91,20 @@ class WebformSubmissionDevelGenerate extends DevelGenerateBase implements Contai */ protected $messenger; - /** - * Constructs a WebformSubmissionDevelGenerate object. - * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack - * The request stack. - * @param \Drupal\Core\Database\Connection $database - * The database. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - * @param \Drupal\Core\Messenger\MessengerInterface $messenger - * The messenger. - * @param \Drupal\webform\WebformSubmissionGenerateInterface $webform_submission_generate - * The webform submission generator. - * @param \Drupal\webform\WebformEntityReferenceManagerInterface $webform_entity_reference_manager - * The webform entity reference manager. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, RequestStack $request_stack, Connection $database, EntityTypeManagerInterface $entity_type_manager, MessengerInterface $messenger, WebformSubmissionGenerateInterface $webform_submission_generate, WebformEntityReferenceManagerInterface $webform_entity_reference_manager) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - - $this->request = $request_stack->getCurrentRequest(); - $this->database = $database; - $this->entityTypeManager = $entity_type_manager; - $this->messenger = $messenger; - $this->webformSubmissionGenerate = $webform_submission_generate; - $this->webformEntityReferenceManager = $webform_entity_reference_manager; - $this->webformStorage = $entity_type_manager->getStorage('webform'); - $this->webformSubmissionStorage = $entity_type_manager->getStorage('webform_submission'); - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('request_stack'), - $container->get('database'), - $container->get('entity_type.manager'), - $container->get('messenger'), - $container->get('webform_submission.generate'), - $container->get('webform.entity_reference_manager') - ); + $instance = parent::create($container, $configuration, $plugin_id, $plugin_definition); + $instance->request = $container->get('request_stack')->getCurrentRequest(); + $instance->database = $container->get('database'); + $instance->entityTypeManager = $container->get('entity_type.manager'); + $instance->messenger = $container->get('messenger'); + $instance->webformSubmissionGenerate = $container->get('webform_submission.generate'); + $instance->webformEntityReferenceManager = $container->get('webform.entity_reference_manager'); + $instance->webformStorage = $container->get('entity_type.manager')->getStorage('webform'); + $instance->webformSubmissionStorage = $container->get('entity_type.manager')->getStorage('webform_submission'); + return $instance; } /** diff --git a/src/Plugin/Field/FieldFormatter/WebformEntityReferenceEntityFormatter.php b/src/Plugin/Field/FieldFormatter/WebformEntityReferenceEntityFormatter.php index c13056eb..6b11d7a8 100644 --- a/src/Plugin/Field/FieldFormatter/WebformEntityReferenceEntityFormatter.php +++ b/src/Plugin/Field/FieldFormatter/WebformEntityReferenceEntityFormatter.php @@ -3,16 +3,10 @@ namespace Drupal\webform\Plugin\Field\FieldFormatter; use Drupal\Core\Access\AccessResult; -use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Serialization\Yaml; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Field\FieldDefinitionInterface; -use Drupal\Core\Render\RendererInterface; -use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\webform\WebformMessageManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -50,60 +44,15 @@ class WebformEntityReferenceEntityFormatter extends WebformEntityReferenceFormat */ protected $messageManager; - /** - * WebformEntityReferenceEntityFormatter constructor. - * - * @param string $plugin_id - * The plugin_id for the formatter. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition - * The definition of the field to which the formatter is associated. - * @param array $settings - * The formatter settings. - * @param string $label - * The formatter label display setting. - * @param string $view_mode - * The view mode. - * @param array $third_party_settings - * Third party settings. - * @param \Drupal\Core\Render\RendererInterface $renderer - * The renderer. - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The factory for configuration objects. - * @param \Drupal\Core\Routing\RouteMatchInterface $route_match - * The route match. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - * @param \Drupal\webform\WebformMessageManagerInterface $message_manager - * The webform message manager. - */ - public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, RendererInterface $renderer, ConfigFactoryInterface $config_factory, RouteMatchInterface $route_match, EntityTypeManagerInterface $entity_type_manager, WebformMessageManagerInterface $message_manager) { - parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings, $renderer, $config_factory); - - $this->routeMatch = $route_match; - $this->entityTypeManager = $entity_type_manager; - $this->messageManager = $message_manager; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $plugin_id, - $plugin_definition, - $configuration['field_definition'], - $configuration['settings'], - $configuration['label'], - $configuration['view_mode'], - $configuration['third_party_settings'], - $container->get('renderer'), - $container->get('config.factory'), - $container->get('current_route_match'), - $container->get('entity_type.manager'), - $container->get('webform.message_manager') - ); + $instance = parent::create($container, $configuration, $plugin_id, $plugin_definition); + $instance->routeMatch = $container->get('current_route_match'); + $instance->entityTypeManager = $container->get('entity_type.manager'); + $instance->messageManager = $container->get('webform.message_manager'); + return $instance; } /** diff --git a/src/Plugin/Field/FieldFormatter/WebformEntityReferenceFormatterBase.php b/src/Plugin/Field/FieldFormatter/WebformEntityReferenceFormatterBase.php index fbf6bd86..c518b209 100644 --- a/src/Plugin/Field/FieldFormatter/WebformEntityReferenceFormatterBase.php +++ b/src/Plugin/Field/FieldFormatter/WebformEntityReferenceFormatterBase.php @@ -2,12 +2,9 @@ namespace Drupal\webform\Plugin\Field\FieldFormatter; -use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Field\EntityReferenceFieldItemListInterface; -use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\Core\Render\RendererInterface; use Drupal\webform\Plugin\Field\FieldType\WebformEntityReferenceItem; use Drupal\webform\WebformInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -31,50 +28,22 @@ abstract class WebformEntityReferenceFormatterBase extends EntityReferenceFormat */ protected $configFactory; - /** - * WebformEntityReferenceLinkFormatter constructor. - * - * @param string $plugin_id - * The plugin_id for the formatter. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition - * The definition of the field to which the formatter is associated. - * @param array $settings - * The formatter settings. - * @param string $label - * The formatter label display setting. - * @param string $view_mode - * The view mode. - * @param array $third_party_settings - * Third party settings. - * @param \Drupal\Core\Render\RendererInterface $renderer - * The renderer. - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The factory for configuration objects. - */ - public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, RendererInterface $renderer, ConfigFactoryInterface $config_factory) { - parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings); - - $this->configFactory = $config_factory; - $this->renderer = $renderer; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( + $instance = new static( $plugin_id, $plugin_definition, $configuration['field_definition'], $configuration['settings'], $configuration['label'], $configuration['view_mode'], - $configuration['third_party_settings'], - $container->get('renderer'), - $container->get('config.factory') + $configuration['third_party_settings'] ); + $instance->configFactory = $container->get('config.factory'); + $instance->renderer = $container->get('renderer'); + return $instance; } /** diff --git a/src/Plugin/Field/FieldFormatter/WebformEntityReferenceLinkFormatter.php b/src/Plugin/Field/FieldFormatter/WebformEntityReferenceLinkFormatter.php index ff9e73b7..dc895e44 100644 --- a/src/Plugin/Field/FieldFormatter/WebformEntityReferenceLinkFormatter.php +++ b/src/Plugin/Field/FieldFormatter/WebformEntityReferenceLinkFormatter.php @@ -2,15 +2,11 @@ namespace Drupal\webform\Plugin\Field\FieldFormatter; -use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Render\RendererInterface; use Drupal\webform\Element\WebformMessage; use Drupal\webform\Entity\WebformSubmission; use Drupal\webform\WebformMessageManagerInterface; -use Drupal\webform\WebformTokenManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -48,56 +44,14 @@ class WebformEntityReferenceLinkFormatter extends WebformEntityReferenceFormatte */ protected $tokenManager; - /** - * WebformEntityReferenceLinkFormatter constructor. - * - * @param string $plugin_id - * The plugin_id for the formatter. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition - * The definition of the field to which the formatter is associated. - * @param array $settings - * The formatter settings. - * @param string $label - * The formatter label display setting. - * @param string $view_mode - * The view mode. - * @param array $third_party_settings - * Third party settings. - * @param \Drupal\Core\Render\RendererInterface $renderer - * The renderer. - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The factory for configuration objects. - * @param \Drupal\webform\WebformMessageManagerInterface $message_manager - * The webform message manager. - * @param \Drupal\webform\WebformTokenManagerInterface $token_manager - * The webform token manager. - */ - public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, RendererInterface $renderer, ConfigFactoryInterface $config_factory, WebformMessageManagerInterface $message_manager, WebformTokenManagerInterface $token_manager) { - parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings, $renderer, $config_factory); - - $this->messageManager = $message_manager; - $this->tokenManager = $token_manager; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $plugin_id, - $plugin_definition, - $configuration['field_definition'], - $configuration['settings'], - $configuration['label'], - $configuration['view_mode'], - $configuration['third_party_settings'], - $container->get('renderer'), - $container->get('config.factory'), - $container->get('webform.message_manager'), - $container->get('webform.token_manager') - ); + $instance = parent::create($container, $configuration, $plugin_id, $plugin_definition); + $instance->messageManager = $container->get('webform.message_manager'); + $instance->tokenManager = $container->get('webform.token_manager'); + return $instance; } /** diff --git a/src/Plugin/WebformElement/WebformManagedFileBase.php b/src/Plugin/WebformElement/WebformManagedFileBase.php index c5dc6465..610d1cb8 100644 --- a/src/Plugin/WebformElement/WebformManagedFileBase.php +++ b/src/Plugin/WebformElement/WebformManagedFileBase.php @@ -5,18 +5,11 @@ namespace Drupal\webform\Plugin\WebformElement; use Drupal\Component\Utility\Bytes; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Unicode; -use Drupal\Component\Transliteration\TransliterationInterface; -use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\EventSubscriber\MainContentViewSubscriber; -use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Link; use Drupal\Core\Render\Element; use Drupal\Core\Url as UrlGenerator; -use Drupal\Core\Render\ElementInfoManagerInterface; -use Drupal\Core\Session\AccountInterface; use Drupal\Core\StreamWrapper\StreamWrapperInterface; use Drupal\file\Entity\File; use Drupal\file\FileInterface; @@ -28,11 +21,7 @@ use Drupal\webform\Utility\WebformOptionsHelper; use Drupal\webform\WebformInterface; use Drupal\webform\WebformSubmissionForm; use Drupal\webform\WebformSubmissionInterface; -use Drupal\webform\Plugin\WebformElementManagerInterface; use Drupal\webform\Plugin\WebformElementEntityReferenceInterface; -use Drupal\webform\WebformLibrariesManagerInterface; -use Drupal\webform\WebformTokenManagerInterface; -use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -80,71 +69,17 @@ abstract class WebformManagedFileBase extends WebformElementBase implements Webf */ protected $languageManager; - /** - * WebformManagedFileBase constructor. - * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Psr\Log\LoggerInterface $logger - * A logger instance. - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The configuration factory. - * @param \Drupal\Core\Session\AccountInterface $current_user - * The current user. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - * @param \Drupal\Core\Render\ElementInfoManagerInterface $element_info - * The element info manager. - * @param \Drupal\webform\Plugin\WebformElementManagerInterface $element_manager - * The webform element manager. - * @param \Drupal\webform\WebformTokenManagerInterface $token_manager - * The webform token manager. - * @param \Drupal\webform\WebformLibrariesManagerInterface $libraries_manager - * The webform libraries manager. - * @param \Drupal\Core\File\FileSystemInterface $file_system - * The file system service. - * @param \Drupal\file\FileUsage\FileUsageInterface|null $file_usage - * The file usage service. - * @param \Drupal\Component\Transliteration\TransliterationInterface $transliteration - * The transliteration service. - * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager - * The language manager. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerInterface $logger, ConfigFactoryInterface $config_factory, AccountInterface $current_user, EntityTypeManagerInterface $entity_type_manager, ElementInfoManagerInterface $element_info, WebformElementManagerInterface $element_manager, WebformTokenManagerInterface $token_manager, WebformLibrariesManagerInterface $libraries_manager, FileSystemInterface $file_system, $file_usage, TransliterationInterface $transliteration, LanguageManagerInterface $language_manager) { - parent::__construct($configuration, $plugin_id, $plugin_definition, $logger, $config_factory, $current_user, $entity_type_manager, $element_info, $element_manager, $token_manager, $libraries_manager); - - $this->fileSystem = $file_system; - $this->fileUsage = $file_usage; - $this->transliteration = $transliteration; - $this->languageManager = $language_manager; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('logger.factory')->get('webform'), - $container->get('config.factory'), - $container->get('current_user'), - $container->get('entity_type.manager'), - $container->get('plugin.manager.element_info'), - $container->get('plugin.manager.webform.element'), - $container->get('webform.token_manager'), - $container->get('webform.libraries_manager'), - $container->get('file_system'), - // We soft depend on "file" module so this service might not be available. - $container->has('file.usage') ? $container->get('file.usage') : NULL, - $container->get('transliteration'), - $container->get('language_manager') - ); + $instance = parent::create($container, $configuration, $plugin_id, $plugin_definition); + $instance->fileSystem = $container->get('file_system'); + // We soft depend on "file" module so this service might not be available. + $instance->fileUsage = $container->has('file.usage') ? $container->get('file.usage') : NULL; + $instance->transliteration = $container->get('transliteration'); + $instance->languageManager = $container->get('language_manager'); + return $instance; } /** diff --git a/src/Plugin/WebformElementBase.php b/src/Plugin/WebformElementBase.php index 87bc5e9b..00e656e1 100644 --- a/src/Plugin/WebformElementBase.php +++ b/src/Plugin/WebformElementBase.php @@ -5,15 +5,12 @@ namespace Drupal\webform\Plugin; use Drupal\Component\Plugin\PluginBase; use Drupal\Component\Utility\NestedArray; use Drupal\Component\Utility\Xss; -use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\OptGroup; use Drupal\Core\Link; use Drupal\Core\Messenger\MessengerTrait; use Drupal\Core\Render\Element; -use Drupal\Core\Render\ElementInfoManagerInterface; use Drupal\Core\Render\Markup; use Drupal\Core\Session\AccountInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; @@ -36,11 +33,8 @@ use Drupal\webform\Utility\WebformHtmlHelper; use Drupal\webform\Utility\WebformOptionsHelper; use Drupal\webform\Utility\WebformReflectionHelper; use Drupal\webform\WebformInterface; -use Drupal\webform\WebformLibrariesManagerInterface; use Drupal\webform\WebformSubmissionConditionsValidator; use Drupal\webform\WebformSubmissionInterface; -use Drupal\webform\WebformTokenManagerInterface; -use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -120,62 +114,23 @@ class WebformElementBase extends PluginBase implements WebformElementInterface { */ protected $submissionStorage; - /** - * Constructs a WebformElementBase object. - * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Psr\Log\LoggerInterface $logger - * A logger instance. - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The configuration factory. - * @param \Drupal\Core\Session\AccountInterface $current_user - * The current user. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - * @param \Drupal\Core\Render\ElementInfoManagerInterface $element_info - * The element info manager. - * @param \Drupal\webform\Plugin\WebformElementManagerInterface $element_manager - * The webform element manager. - * @param \Drupal\webform\WebformTokenManagerInterface $token_manager - * The webform token manager. - * @param \Drupal\webform\WebformLibrariesManagerInterface $libraries_manager - * The webform libraries manager. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerInterface $logger, ConfigFactoryInterface $config_factory, AccountInterface $current_user, EntityTypeManagerInterface $entity_type_manager, ElementInfoManagerInterface $element_info, WebformElementManagerInterface $element_manager, WebformTokenManagerInterface $token_manager, WebformLibrariesManagerInterface $libraries_manager) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->logger = $logger; - $this->configFactory = $config_factory; - $this->currentUser = $current_user; - $this->entityTypeManager = $entity_type_manager; - $this->elementInfo = $element_info; - $this->elementManager = $element_manager; - $this->tokenManager = $token_manager; - $this->librariesManager = $libraries_manager; - $this->submissionStorage = $entity_type_manager->getStorage('webform_submission'); - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('logger.factory')->get('webform'), - $container->get('config.factory'), - $container->get('current_user'), - $container->get('entity_type.manager'), - $container->get('plugin.manager.element_info'), - $container->get('plugin.manager.webform.element'), - $container->get('webform.token_manager'), - $container->get('webform.libraries_manager') - ); + $instance = new static($configuration, $plugin_id, $plugin_definition); + + $instance->logger = $container->get('logger.factory')->get('webform'); + $instance->configFactory = $container->get('config.factory'); + $instance->currentUser = $container->get('current_user'); + $instance->entityTypeManager = $container->get('entity_type.manager'); + $instance->elementInfo = $container->get('plugin.manager.element_info'); + $instance->elementManager = $container->get('plugin.manager.webform.element'); + $instance->tokenManager = $container->get('webform.token_manager'); + $instance->librariesManager = $container->get('webform.libraries_manager'); + $instance->submissionStorage = $container->get('entity_type.manager')->getStorage('webform_submission'); + + return $instance; } /****************************************************************************/ diff --git a/src/Plugin/WebformExporterBase.php b/src/Plugin/WebformExporterBase.php index df9a0903..8bc63dad 100644 --- a/src/Plugin/WebformExporterBase.php +++ b/src/Plugin/WebformExporterBase.php @@ -2,13 +2,9 @@ namespace Drupal\webform\Plugin; -use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginBase; -use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\webform\WebformSubmissionInterface; -use Drupal\webform\WebformTokenManagerInterface; -use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -63,52 +59,22 @@ abstract class WebformExporterBase extends PluginBase implements WebformExporter */ protected $tokenManager; - /** - * Constructs a WebformExporterBase object. - * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Psr\Log\LoggerInterface $logger - * A logger instance. - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The configuration factory. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - * @param \Drupal\webform\Plugin\WebformElementManagerInterface $element_manager - * The webform element manager. - * @param \Drupal\webform\WebformTokenManagerInterface $token_manager - * The webform token manager. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerInterface $logger, ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, WebformElementManagerInterface $element_manager, WebformTokenManagerInterface $token_manager) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - - $this->setConfiguration($configuration); - $this->logger = $logger; - $this->configFactory = $config_factory; - $this->entityTypeManager = $entity_type_manager; - $this->entityStorage = $entity_type_manager->getStorage('webform_submission'); - $this->elementManager = $element_manager; - $this->tokenManager = $token_manager; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('logger.factory')->get('webform'), - $container->get('config.factory'), - $container->get('entity_type.manager'), - $container->get('plugin.manager.webform.element'), - $container->get('webform.token_manager') - ); + $instance = new static($configuration, $plugin_id, $plugin_definition); + + $instance->logger = $container->get('logger.factory')->get('webform'); + $instance->configFactory = $container->get('config.factory'); + $instance->entityTypeManager = $container->get('entity_type.manager'); + $instance->entityStorage = $container->get('entity_type.manager')->getStorage('webform_submission'); + $instance->elementManager = $container->get('plugin.manager.webform.element'); + $instance->tokenManager = $container->get('webform.token_manager'); + + $instance->setConfiguration($configuration); + + return $instance; } /** diff --git a/src/Plugin/WebformHandler/ActionWebformHandler.php b/src/Plugin/WebformHandler/ActionWebformHandler.php index 5272b54e..28e2fc7b 100644 --- a/src/Plugin/WebformHandler/ActionWebformHandler.php +++ b/src/Plugin/WebformHandler/ActionWebformHandler.php @@ -2,16 +2,11 @@ namespace Drupal\webform\Plugin\WebformHandler; -use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Serialization\Yaml; -use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\webform\Element\WebformHtmlEditor; use Drupal\webform\Plugin\WebformHandlerBase; -use Drupal\webform\WebformSubmissionConditionsValidatorInterface; use Drupal\webform\WebformSubmissionInterface; -use Drupal\webform\WebformTokenManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -37,28 +32,13 @@ class ActionWebformHandler extends WebformHandlerBase { */ protected $tokenManager; - /** - * {@inheritdoc} - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerChannelFactoryInterface $logger_factory, ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, WebformSubmissionConditionsValidatorInterface $conditions_validator, WebformTokenManagerInterface $token_manager) { - parent::__construct($configuration, $plugin_id, $plugin_definition, $logger_factory, $config_factory, $entity_type_manager, $conditions_validator); - $this->tokenManager = $token_manager; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('logger.factory'), - $container->get('config.factory'), - $container->get('entity_type.manager'), - $container->get('webform_submission.conditions_validator'), - $container->get('webform.token_manager') - ); + $instance = parent::create($container, $configuration, $plugin_id, $plugin_definition); + $instance->tokenManager = $container->get('webform.token_manager'); + return $instance; } /** diff --git a/src/Plugin/WebformHandler/EmailWebformHandler.php b/src/Plugin/WebformHandler/EmailWebformHandler.php index bb8b449f..69bd1f33 100644 --- a/src/Plugin/WebformHandler/EmailWebformHandler.php +++ b/src/Plugin/WebformHandler/EmailWebformHandler.php @@ -5,30 +5,19 @@ namespace Drupal\webform\Plugin\WebformHandler; use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\NestedArray; -use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Language\LanguageManagerInterface; -use Drupal\Core\Logger\LoggerChannelFactoryInterface; -use Drupal\Core\Mail\MailManagerInterface; use Drupal\Core\Render\Markup; -use Drupal\Core\Session\AccountInterface; use Drupal\Core\Url; use Drupal\webform\Element\WebformMessage; use Drupal\webform\Element\WebformSelectOther; use Drupal\webform\Plugin\WebformElement\WebformCompositeBase; -use Drupal\webform\Plugin\WebformElementManagerInterface; use Drupal\webform\Plugin\WebformHandlerBase; use Drupal\webform\Plugin\WebformHandlerMessageInterface; use Drupal\webform\Twig\WebformTwigExtension; use Drupal\webform\Utility\Mail; use Drupal\webform\Utility\WebformElementHelper; use Drupal\webform\Utility\WebformOptionsHelper; -use Drupal\webform\WebformSubmissionConditionsValidatorInterface; use Drupal\webform\WebformSubmissionInterface; -use Drupal\webform\WebformThemeManagerInterface; -use Drupal\webform\WebformTokenManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -132,40 +121,19 @@ class EmailWebformHandler extends WebformHandlerBase implements WebformHandlerMe */ protected $defaultValues; - /** - * {@inheritdoc} - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerChannelFactoryInterface $logger_factory, ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, WebformSubmissionConditionsValidatorInterface $conditions_validator, AccountInterface $current_user, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager, MailManagerInterface $mail_manager, WebformThemeManagerInterface $theme_manager, WebformTokenManagerInterface $token_manager, WebformElementManagerInterface $element_manager) { - parent::__construct($configuration, $plugin_id, $plugin_definition, $logger_factory, $config_factory, $entity_type_manager, $conditions_validator); - $this->currentUser = $current_user; - $this->moduleHandler = $module_handler; - $this->languageManager = $language_manager; - $this->mailManager = $mail_manager; - $this->themeManager = $theme_manager; - $this->tokenManager = $token_manager; - $this->elementManager = $element_manager; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('logger.factory'), - $container->get('config.factory'), - $container->get('entity_type.manager'), - $container->get('webform_submission.conditions_validator'), - $container->get('current_user'), - $container->get('module_handler'), - $container->get('language_manager'), - $container->get('plugin.manager.mail'), - $container->get('webform.theme_manager'), - $container->get('webform.token_manager'), - $container->get('plugin.manager.webform.element') - ); + $instance = parent::create($container, $configuration, $plugin_id, $plugin_definition); + $instance->currentUser = $container->get('current_user'); + $instance->moduleHandler = $container->get('module_handler'); + $instance->languageManager = $container->get('language_manager'); + $instance->mailManager = $container->get('plugin.manager.mail'); + $instance->themeManager = $container->get('webform.theme_manager'); + $instance->tokenManager = $container->get('webform.token_manager'); + $instance->elementManager = $container->get('plugin.manager.webform.element'); + return $instance; } /** diff --git a/src/Plugin/WebformHandler/RemotePostWebformHandler.php b/src/Plugin/WebformHandler/RemotePostWebformHandler.php index 3c60e64c..b38d0064 100644 --- a/src/Plugin/WebformHandler/RemotePostWebformHandler.php +++ b/src/Plugin/WebformHandler/RemotePostWebformHandler.php @@ -2,25 +2,17 @@ namespace Drupal\webform\Plugin\WebformHandler; -use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Routing\TrustedRedirectResponse; use Drupal\Core\Serialization\Yaml; -use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; use Drupal\file\Entity\File; use Drupal\webform\Element\WebformMessage; use Drupal\webform\Plugin\WebformElement\WebformManagedFileBase; -use Drupal\webform\Plugin\WebformElementManagerInterface; use Drupal\webform\Plugin\WebformHandlerBase; use Drupal\webform\WebformInterface; use Drupal\webform\WebformMessageManagerInterface; -use Drupal\webform\WebformSubmissionConditionsValidatorInterface; use Drupal\webform\WebformSubmissionInterface; -use Drupal\webform\WebformTokenManagerInterface; -use GuzzleHttp\ClientInterface; use GuzzleHttp\Exception\RequestException; use Psr\Http\Message\ResponseInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -87,36 +79,17 @@ class RemotePostWebformHandler extends WebformHandlerBase { 'metatag', ]; - /** - * {@inheritdoc} - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerChannelFactoryInterface $logger_factory, ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, WebformSubmissionConditionsValidatorInterface $conditions_validator, ModuleHandlerInterface $module_handler, ClientInterface $http_client, WebformTokenManagerInterface $token_manager, WebformMessageManagerInterface $message_manager, WebformElementManagerInterface $element_manager) { - parent::__construct($configuration, $plugin_id, $plugin_definition, $logger_factory, $config_factory, $entity_type_manager, $conditions_validator); - $this->moduleHandler = $module_handler; - $this->httpClient = $http_client; - $this->tokenManager = $token_manager; - $this->messageManager = $message_manager; - $this->elementManager = $element_manager; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('logger.factory'), - $container->get('config.factory'), - $container->get('entity_type.manager'), - $container->get('webform_submission.conditions_validator'), - $container->get('module_handler'), - $container->get('http_client'), - $container->get('webform.token_manager'), - $container->get('webform.message_manager'), - $container->get('plugin.manager.webform.element') - ); + $instance = parent::create($container, $configuration, $plugin_id, $plugin_definition); + $instance->moduleHandler = $container->get('module_handler'); + $instance->httpClient = $container->get('http_client'); + $instance->tokenManager = $container->get('webform.token_manager'); + $instance->messageManager = $container->get('webform.message_manager'); + $instance->elementManager = $container->get('plugin.manager.webform.element'); + return $instance; } /** diff --git a/src/Plugin/WebformHandler/SettingsWebformHandler.php b/src/Plugin/WebformHandler/SettingsWebformHandler.php index 9cceace5..d1855177 100644 --- a/src/Plugin/WebformHandler/SettingsWebformHandler.php +++ b/src/Plugin/WebformHandler/SettingsWebformHandler.php @@ -3,18 +3,12 @@ namespace Drupal\webform\Plugin\WebformHandler; use Drupal\Component\Utility\Unicode; -use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Config\TypedConfigManagerInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Logger\LoggerChannelFactoryInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\webform\Entity\Webform; use Drupal\webform\Plugin\WebformHandlerBase; use Drupal\webform\Utility\WebformArrayHelper; use Drupal\webform\WebformInterface; -use Drupal\webform\WebformSubmissionConditionsValidatorInterface; use Drupal\webform\WebformSubmissionInterface; -use Drupal\webform\WebformTokenManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -47,30 +41,14 @@ class SettingsWebformHandler extends WebformHandlerBase { */ protected $tokenManager; - /** - * {@inheritdoc} - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerChannelFactoryInterface $logger_factory, ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, WebformSubmissionConditionsValidatorInterface $conditions_validator, TypedConfigManagerInterface $typed_config, WebformTokenManagerInterface $token_manager) { - parent::__construct($configuration, $plugin_id, $plugin_definition, $logger_factory, $config_factory, $entity_type_manager, $conditions_validator); - $this->typedConfigManager = $typed_config; - $this->tokenManager = $token_manager; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('logger.factory'), - $container->get('config.factory'), - $container->get('entity_type.manager'), - $container->get('webform_submission.conditions_validator'), - $container->get('config.typed'), - $container->get('webform.token_manager') - ); + $instance = parent::create($container, $configuration, $plugin_id, $plugin_definition); + $instance->typedConfigManager = $container->get('config.typed'); + $instance->tokenManager = $container->get('webform.token_manager'); + return $instance; } /** diff --git a/src/Plugin/WebformHandlerBase.php b/src/Plugin/WebformHandlerBase.php index 8b1fc801..0de9a610 100644 --- a/src/Plugin/WebformHandlerBase.php +++ b/src/Plugin/WebformHandlerBase.php @@ -2,15 +2,11 @@ namespace Drupal\webform\Plugin; -use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Plugin\PluginBase; use Drupal\webform\Utility\WebformElementHelper; use Drupal\webform\WebformInterface; -use Drupal\webform\WebformSubmissionConditionsValidatorInterface; use Drupal\webform\WebformSubmissionInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -109,7 +105,7 @@ abstract class WebformHandlerBase extends PluginBase implements WebformHandlerIn protected $tokenManager; /** - * Constructs a WebformHandlerBase object. + * {@inheritdoc} * * IMPORTANT: * Webform handlers are initialized and serialized when they are attached to a @@ -119,49 +115,19 @@ abstract class WebformHandlerBase extends PluginBase implements WebformHandlerIn * from being thrown when a form is serialized via an Ajax callback and/or * form build. * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_factory - * The logger factory. - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The configuration factory. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - * @param \Drupal\webform\WebformSubmissionConditionsValidatorInterface $conditions_validator - * The webform submission conditions (#states) validator. - * - * @see \Drupal\webform\Entity\Webform::getHandlers */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerChannelFactoryInterface $logger_factory, ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, WebformSubmissionConditionsValidatorInterface $conditions_validator) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->setConfiguration($configuration); - $this->loggerFactory = $logger_factory; - $this->configFactory = $config_factory; - $this->submissionStorage = $entity_type_manager->getStorage('webform_submission'); - $this->conditionsValidator = $conditions_validator; + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + $instance = new static($configuration, $plugin_id, $plugin_definition); - // @todo Webform 8.x-6.x: Properly inject the token manager. - // @todo Webform 8.x-6.x: Update handlers that injects the token manager. - $this->tokenManager = \Drupal::service('webform.token_manager'); - } + $instance->loggerFactory = $container->get('logger.factory'); + $instance->configFactory = $container->get('config.factory'); + $instance->submissionStorage = $container->get('entity_type.manager')->getStorage('webform_submission'); + $instance->conditionsValidator = $container->get('webform_submission.conditions_validator'); + $instance->tokenManager = $container->get('webform.token_manager'); - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('logger.factory'), - $container->get('config.factory'), - $container->get('entity_type.manager'), - $container->get('webform_submission.conditions_validator') - ); + $instance->setConfiguration($configuration); + + return $instance; } /** diff --git a/src/Plugin/WebformSourceEntity/QueryStringWebformSourceEntity.php b/src/Plugin/WebformSourceEntity/QueryStringWebformSourceEntity.php index 633e471e..592b555f 100644 --- a/src/Plugin/WebformSourceEntity/QueryStringWebformSourceEntity.php +++ b/src/Plugin/WebformSourceEntity/QueryStringWebformSourceEntity.php @@ -2,16 +2,9 @@ namespace Drupal\webform\Plugin\WebformSourceEntity; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Language\LanguageManagerInterface; -use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\Core\Plugin\PluginBase; -use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\TypedData\TranslatableInterface; -use Drupal\webform\Plugin\WebformSourceEntityInterface; -use Drupal\webform\WebformEntityReferenceManagerInterface; +use Drupal\webform\Plugin\WebformSourceEntityBase; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpFoundation\RequestStack; /** * Detect source entity by examining query string. @@ -22,7 +15,7 @@ use Symfony\Component\HttpFoundation\RequestStack; * weight = 0 * ) */ -class QueryStringWebformSourceEntity extends PluginBase implements WebformSourceEntityInterface, ContainerFactoryPluginInterface { +class QueryStringWebformSourceEntity extends WebformSourceEntityBase { /** * Entity type manager service. @@ -59,50 +52,17 @@ class QueryStringWebformSourceEntity extends PluginBase implements WebformSource */ protected $webformEntityReferenceManager; - /** - * QueryStringWebformSourceEntity constructor. - * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The "entity_type.manager" service. - * @param \Drupal\Core\Routing\RouteMatchInterface $route_match - * The "current_route_match" service. - * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack - * The "request_stack" service. - * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager - * The "language_manager" service. - * @param \Drupal\webform\WebformEntityReferenceManagerInterface $webform_entity_reference_manager - * The "webform.entity_reference_manager" service. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, RouteMatchInterface $route_match, RequestStack $request_stack, LanguageManagerInterface $language_manager, WebformEntityReferenceManagerInterface $webform_entity_reference_manager) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - - $this->entityTypeManager = $entity_type_manager; - $this->routeMatch = $route_match; - $this->request = $request_stack->getCurrentRequest(); - $this->languageManager = $language_manager; - $this->webformEntityReferenceManager = $webform_entity_reference_manager; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('entity_type.manager'), - $container->get('current_route_match'), - $container->get('request_stack'), - $container->get('language_manager'), - $container->get('webform.entity_reference_manager') - ); + $instance = parent::create($container, $configuration, $plugin_id, $plugin_definition); + $instance->entityTypeManager = $container->get('entity_type.manager'); + $instance->routeMatch = $container->get('current_route_match'); + $instance->request = $container->get('request_stack')->getCurrentRequest(); + $instance->languageManager = $container->get('language_manager'); + $instance->webformEntityReferenceManager = $container->get('webform.entity_reference_manager'); + return $instance; } /** diff --git a/src/Plugin/WebformSourceEntity/RouteParametersWebformSourceEntity.php b/src/Plugin/WebformSourceEntity/RouteParametersWebformSourceEntity.php index fba4d626..5d1fe257 100644 --- a/src/Plugin/WebformSourceEntity/RouteParametersWebformSourceEntity.php +++ b/src/Plugin/WebformSourceEntity/RouteParametersWebformSourceEntity.php @@ -3,10 +3,7 @@ namespace Drupal\webform\Plugin\WebformSourceEntity; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\Core\Plugin\PluginBase; -use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\webform\Plugin\WebformSourceEntityInterface; +use Drupal\webform\Plugin\WebformSourceEntityBase; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -18,7 +15,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * weight = 100 * ) */ -class RouteParametersWebformSourceEntity extends PluginBase implements WebformSourceEntityInterface, ContainerFactoryPluginInterface { +class RouteParametersWebformSourceEntity extends WebformSourceEntityBase { /** * Current route match service. @@ -27,34 +24,13 @@ class RouteParametersWebformSourceEntity extends PluginBase implements WebformSo */ protected $routeMatch; - /** - * RouteParametersWebformSourceEntity constructor. - * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Drupal\Core\Routing\RouteMatchInterface $route_match - * The "current_route_match" service. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteMatchInterface $route_match) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - - $this->routeMatch = $route_match; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('current_route_match') - ); + $instance = parent::create($container, $configuration, $plugin_id, $plugin_definition); + $instance->routeMatch = $container->get('current_route_match'); + return $instance; } /** diff --git a/src/Plugin/WebformSourceEntityBase.php b/src/Plugin/WebformSourceEntityBase.php new file mode 100644 index 00000000..00f47851 --- /dev/null +++ b/src/Plugin/WebformSourceEntityBase.php @@ -0,0 +1,25 @@ +requestStack = $request_stack; - $this->entityTypeManager = $entity_type_manager; - $this->webformSourceEntityManager = $webform_source_entity_manager; - $this->accessRulesManager = $access_rules_manager; - } - /** * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $entity_type, - $container->get('request_stack'), - $container->get('entity_type.manager'), - $container->get('plugin.manager.webform.source_entity'), - $container->get('webform.access_rules_manager') - ); + $instance = new static($entity_type); + $instance->requestStack = $container->get('request_stack'); + $instance->entityTypeManager = $container->get('entity_type.manager'); + $instance->webformSourceEntityManager = $container->get('plugin.manager.webform.source_entity'); + $instance->accessRulesManager = $container->get('webform.access_rules_manager'); + return $instance; } /** diff --git a/src/WebformEntityListBuilder.php b/src/WebformEntityListBuilder.php index 9ee1b53d..2d373f3c 100644 --- a/src/WebformEntityListBuilder.php +++ b/src/WebformEntityListBuilder.php @@ -4,16 +4,12 @@ namespace Drupal\webform; use Drupal\Core\Config\Entity\ConfigEntityListBuilder; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Session\AccountInterface; use Drupal\Core\Url; use Drupal\webform\Element\WebformHtmlEditor; use Drupal\webform\Utility\WebformDialogHelper; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpFoundation\RequestStack; /** * Defines a class to build a listing of webform entities. @@ -79,43 +75,31 @@ class WebformEntityListBuilder extends ConfigEntityListBuilder { protected $roleStorage; /** - * Constructs a new WebformListBuilder object. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type definition. - * @param \Drupal\Core\Entity\EntityStorageInterface $storage - * The entity storage class. - * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack - * The request stack. - * @param \Drupal\Core\Session\AccountInterface $current_user - * The current user. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. + * {@inheritdoc} */ - public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, RequestStack $request_stack, AccountInterface $current_user, EntityTypeManagerInterface $entity_type_manager) { - parent::__construct($entity_type, $storage); - $this->request = $request_stack->getCurrentRequest(); - $this->currentUser = $current_user; + public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { + /** @var \Drupal\webform\WebformEntityListBuilder $instance */ + $instance = parent::createInstance($container, $entity_type); - $this->keys = $this->request->query->get('search'); - $this->category = $this->request->query->get('category'); - $this->state = $this->request->query->get('state'); - $this->submissionStorage = $entity_type_manager->getStorage('webform_submission'); - $this->userStorage = $entity_type_manager->getStorage('user'); - $this->roleStorage = $entity_type_manager->getStorage('user_role'); + $entity_type_manager = $container->get('entity_type.manager'); + + $instance->request = $container->get('request_stack')->getCurrentRequest(); + $instance->currentUser = $container->get('current_user'); + $instance->submissionStorage = $entity_type_manager->getStorage('webform_submission'); + $instance->userStorage = $entity_type_manager->getStorage('user'); + $instance->roleStorage = $entity_type_manager->getStorage('user_role'); + + $instance->initialize(); + return $instance; } /** - * {@inheritdoc} + * Initialize WebformEntityListBuilder object. */ - public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $entity_type, - $container->get('entity_type.manager')->getStorage($entity_type->id()), - $container->get('request_stack'), - $container->get('current_user'), - $container->get('entity_type.manager') - ); + protected function initialize() { + $this->keys = $this->request->query->get('search'); + $this->category = $this->request->query->get('category'); + $this->state = $this->request->query->get('state'); } /** diff --git a/src/WebformEntityStorage.php b/src/WebformEntityStorage.php index 7282c345..c4919008 100644 --- a/src/WebformEntityStorage.php +++ b/src/WebformEntityStorage.php @@ -2,16 +2,10 @@ namespace Drupal\webform; -use Drupal\Component\Uuid\UuidInterface; use Drupal\Core\Cache\Cache; -use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface; -use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\Entity\ConfigEntityStorage; -use Drupal\Core\Database\Connection; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\StreamWrapper\StreamWrapperInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -41,45 +35,14 @@ class WebformEntityStorage extends ConfigEntityStorage implements WebformEntityS */ protected $totals; - /** - * Constructs a WebformEntityStorage object. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type definition. - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The config factory service. - * @param \Drupal\Component\Uuid\UuidInterface $uuid_service - * The UUID service. - * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager - * The language manager. - * @param \Drupal\Core\Database\Connection $database - * The database connection to be used. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager service. - * @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface $memory_cache - * The memory cache. - * - * @todo Webform 8.x-6.x: Move $memory_cache right after $language_manager. - */ - public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, Connection $database, EntityTypeManagerInterface $entity_type_manager, MemoryCacheInterface $memory_cache = NULL) { - parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager, $memory_cache); - $this->database = $database; - $this->entityTypeManager = $entity_type_manager; - } - /** * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $entity_type, - $container->get('config.factory'), - $container->get('uuid'), - $container->get('language_manager'), - $container->get('database'), - $container->get('entity_type.manager'), - $container->get('entity.memory_cache') - ); + $instance = parent::createInstance($container, $entity_type); + $instance->database = $container->get('database'); + $instance->entityTypeManager = $container->get('entity_type.manager'); + return $instance; } /** diff --git a/src/WebformOptionsListBuilder.php b/src/WebformOptionsListBuilder.php index 6f32a5cb..63f7e5a9 100644 --- a/src/WebformOptionsListBuilder.php +++ b/src/WebformOptionsListBuilder.php @@ -4,7 +4,6 @@ namespace Drupal\webform; use Drupal\Core\Config\Entity\ConfigEntityListBuilder; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Form\OptGroup; use Drupal\Core\Url; @@ -12,7 +11,6 @@ use Drupal\webform\Entity\WebformOptions; use Drupal\webform\Utility\WebformDialogHelper; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpFoundation\RequestStack; /** * Defines a class to build a listing of webform options entities. @@ -36,32 +34,24 @@ class WebformOptionsListBuilder extends ConfigEntityListBuilder { protected $category; /** - * Constructs a new WebformOptionsListBuilder object. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type definition. - * @param \Drupal\Core\Entity\EntityStorageInterface $storage - * The entity storage class. - * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack - * The request stack. + * {@inheritdoc} */ - public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, RequestStack $request_stack) { - parent::__construct($entity_type, $storage); - $this->request = $request_stack->getCurrentRequest(); + public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { + /** @var \Drupal\webform\WebformOptionsListBuilder $instance */ + $instance = parent::createInstance($container, $entity_type); - $this->keys = $this->request->query->get('search'); - $this->category = $this->request->query->get('category'); + $instance->request = $container->get('request_stack')->getCurrentRequest(); + + $instance->initialize(); + return $instance; } /** - * {@inheritdoc} + * Initialize WebformOptionsListBuilder object. */ - public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $entity_type, - $container->get('entity.manager')->getStorage($entity_type->id()), - $container->get('request_stack') - ); + protected function initialize() { + $this->keys = $this->request->query->get('search'); + $this->category = $this->request->query->get('category'); } /** diff --git a/src/WebformOptionsStorage.php b/src/WebformOptionsStorage.php index 7da11752..fa394c1c 100644 --- a/src/WebformOptionsStorage.php +++ b/src/WebformOptionsStorage.php @@ -3,16 +3,10 @@ namespace Drupal\webform; use Drupal\Component\Render\FormattableMarkup; -use Drupal\Component\Uuid\UuidInterface; -use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface; -use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\Entity\ConfigEntityStorage; use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Language\LanguageManagerInterface; -use Drupal\Core\Render\ElementInfoManagerInterface; use Drupal\Core\Serialization\Yaml; use Drupal\webform\Element\WebformCompositeBase; -use Drupal\webform\Plugin\WebformElementManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -48,45 +42,14 @@ class WebformOptionsStorage extends ConfigEntityStorage implements WebformOption */ protected $usedByWebforms; - /** - * Constructs a WebformOptionsStorage object. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type definition. - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The config factory service. - * @param \Drupal\Component\Uuid\UuidInterface $uuid_service - * The UUID service. - * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager - * The language manager. - * @param \Drupal\Core\Render\ElementInfoManagerInterface $element_info - * The element info manager. - * @param \Drupal\webform\Plugin\WebformElementManagerInterface $element_manager - * The webform element manager. - * @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface $memory_cache - * The memory cache. - * - * @todo Webform 8.x-6.x: Move $memory_cache right after $language_manager. - */ - public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, ElementInfoManagerInterface $element_info, WebformElementManagerInterface $element_manager, MemoryCacheInterface $memory_cache = NULL) { - parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager, $memory_cache); - $this->elementInfo = $element_info; - $this->elementManager = $element_manager; - } - /** * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $entity_type, - $container->get('config.factory'), - $container->get('uuid'), - $container->get('language_manager'), - $container->get('plugin.manager.element_info'), - $container->get('plugin.manager.webform.element'), - $container->get('entity.memory_cache') - ); + $instance = parent::createInstance($container, $entity_type); + $instance->elementInfo = $container->get('plugin.manager.element_info'); + $instance->elementManager = $container->get('plugin.manager.webform.element'); + return $instance; } /** diff --git a/src/WebformSubmissionAccessControlHandler.php b/src/WebformSubmissionAccessControlHandler.php index defea601..e1921976 100644 --- a/src/WebformSubmissionAccessControlHandler.php +++ b/src/WebformSubmissionAccessControlHandler.php @@ -24,28 +24,14 @@ class WebformSubmissionAccessControlHandler extends EntityAccessControlHandler i */ protected $accessRulesManager; - /** - * WebformSubmissionAccessControlHandler constructor. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type definition. - * @param \Drupal\webform\WebformAccessRulesManagerInterface $access_rules_manager - * Webform access rules manager service. - */ - public function __construct(EntityTypeInterface $entity_type, WebformAccessRulesManagerInterface $access_rules_manager) { - parent::__construct($entity_type); - - $this->accessRulesManager = $access_rules_manager; - } - /** * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $entity_type, - $container->get('webform.access_rules_manager') - ); + $instance = new static($entity_type); + $instance->accessRulesManager = $container->get('webform.access_rules_manager'); + return $instance; + } /** diff --git a/src/WebformSubmissionForm.php b/src/WebformSubmissionForm.php index 36e8849d..5925af79 100644 --- a/src/WebformSubmissionForm.php +++ b/src/WebformSubmissionForm.php @@ -7,25 +7,18 @@ use Drupal\Component\Utility\Bytes; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Cache\Cache; -use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityRepositoryInterface; use Drupal\Core\Entity\ContentEntityForm; use Drupal\Core\Form\FormState; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Messenger\MessengerInterface; -use Drupal\Core\PageCache\ResponsePolicy\KillSwitch; -use Drupal\Core\Path\AliasManagerInterface; -use Drupal\Core\Path\PathValidatorInterface; use Drupal\Core\Render\Element; -use Drupal\Core\Render\RendererInterface; use Drupal\Core\Routing\TrustedRedirectResponse; use Drupal\Core\Template\Attribute; use Drupal\Core\Url; use Drupal\webform\Entity\WebformSubmission; use Drupal\webform\Form\WebformDialogFormTrait; use Drupal\webform\Plugin\WebformElement\Hidden; -use Drupal\webform\Plugin\WebformElementManagerInterface; use Drupal\webform\Plugin\WebformElementWizardPageInterface; use Drupal\webform\Plugin\WebformHandlerInterface; use Drupal\webform\Plugin\WebformSourceEntityManager; @@ -56,6 +49,13 @@ class WebformSubmissionForm extends ContentEntityForm { */ protected $renderer; + /** + * The kill switch. + * + * @var \Drupal\Core\PageCache\ResponsePolicy\KillSwitch + */ + protected $killSwitch; + /** * The path alias manager. * @@ -147,99 +147,25 @@ class WebformSubmissionForm extends ContentEntityForm { */ protected $statesPrefix; - /** - * The kill switch. - * - * @var \Drupal\Core\PageCache\ResponsePolicy\KillSwitch - */ - protected $killSwitch; - - /** - * Constructs a WebformSubmissionForm object. - * - * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository - * The entity repository. - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager. - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The factory for configuration objects. - * @param \Drupal\Core\Render\RendererInterface $renderer - * The renderer service. - * @param \Drupal\Core\Path\AliasManagerInterface $alias_manager - * The path alias manager. - * @param \Drupal\Core\Path\PathValidatorInterface $path_validator - * The path validator. - * @param \Drupal\webform\WebformRequestInterface $request_handler - * The webform request handler. - * @param \Drupal\webform\Plugin\WebformElementManagerInterface $element_manager - * The webform element manager. - * @param \Drupal\webform\WebformThirdPartySettingsManagerInterface $third_party_settings_manager - * The webform third party settings manager. - * @param \Drupal\webform\WebformMessageManagerInterface $message_manager - * The webform message manager. - * @param \Drupal\webform\WebformTokenManagerInterface $token_manager - * The webform token manager. - * @param \Drupal\webform\WebformSubmissionConditionsValidatorInterface $conditions_validator - * The webform submission conditions (#states) validator. - * @param \Drupal\webform\WebformEntityReferenceManagerInterface $webform_entity_reference_manager - * The webform entity reference manager. - * @param \Drupal\webform\WebformSubmissionGenerateInterface $submission_generate - * The webform submission generation service. - * @param \Drupal\Core\PageCache\ResponsePolicy\KillSwitch $killSwitch - * The page cache kill switch service. - */ - public function __construct( - EntityRepositoryInterface $entity_repository, - ConfigFactoryInterface $config_factory, - RendererInterface $renderer, - AliasManagerInterface $alias_manager, - PathValidatorInterface $path_validator, - WebformRequestInterface $request_handler, - WebformElementManagerInterface $element_manager, - WebformThirdPartySettingsManagerInterface $third_party_settings_manager, - WebformMessageManagerInterface $message_manager, - WebformTokenManagerInterface $token_manager, - WebformSubmissionConditionsValidatorInterface $conditions_validator, - WebformEntityReferenceManagerInterface $webform_entity_reference_manager, - WebformSubmissionGenerateInterface $submission_generate, - KillSwitch $killSwitch - ) { - parent::__construct($entity_repository); - $this->configFactory = $config_factory; - $this->renderer = $renderer; - $this->requestHandler = $request_handler; - $this->aliasManager = $alias_manager; - $this->pathValidator = $path_validator; - $this->elementManager = $element_manager; - $this->thirdPartySettingsManager = $third_party_settings_manager; - $this->messageManager = $message_manager; - $this->tokenManager = $token_manager; - $this->conditionsValidator = $conditions_validator; - $this->webformEntityReferenceManager = $webform_entity_reference_manager; - $this->generate = $submission_generate; - $this->killSwitch = $killSwitch; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static( - $container->get('entity.repository'), - $container->get('config.factory'), - $container->get('renderer'), - $container->get('path.alias_manager'), - $container->get('path.validator'), - $container->get('webform.request'), - $container->get('plugin.manager.webform.element'), - $container->get('webform.third_party_settings_manager'), - $container->get('webform.message_manager'), - $container->get('webform.token_manager'), - $container->get('webform_submission.conditions_validator'), - $container->get('webform.entity_reference_manager'), - $container->get('webform_submission.generate'), - $container->get('page_cache_kill_switch') - ); + $instance = parent::create($container); + $instance->configFactory = $container->get('config.factory'); + $instance->renderer = $container->get('renderer'); + $instance->killSwitch = $container->get('page_cache_kill_switch'); + $instance->requestHandler = $container->get('webform.request'); + $instance->aliasManager = $container->get('path.alias_manager'); + $instance->pathValidator = $container->get('path.validator'); + $instance->elementManager = $container->get('plugin.manager.webform.element'); + $instance->thirdPartySettingsManager = $container->get('webform.third_party_settings_manager'); + $instance->messageManager = $container->get('webform.message_manager'); + $instance->tokenManager = $container->get('webform.token_manager'); + $instance->conditionsValidator = $container->get('webform_submission.conditions_validator'); + $instance->webformEntityReferenceManager = $container->get('webform.entity_reference_manager'); + $instance->generate = $container->get('webform_submission.generate'); + return $instance; } /** @@ -516,7 +442,7 @@ class WebformSubmissionForm extends ContentEntityForm { // Server side #states API validation. $this->conditionsValidator->buildForm($form, $form_state); - + return $form; } diff --git a/src/WebformSubmissionListBuilder.php b/src/WebformSubmissionListBuilder.php index 243895c9..043e7105 100644 --- a/src/WebformSubmissionListBuilder.php +++ b/src/WebformSubmissionListBuilder.php @@ -3,24 +3,17 @@ namespace Drupal\webform; use Drupal\Component\Render\FormattableMarkup; -use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Database\Database; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityListBuilder; -use Drupal\Core\Entity\EntityStorageInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Link; -use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\Core\Session\AccountInterface; use Drupal\Core\Url; use Drupal\views\Views; use Drupal\webform\Controller\WebformSubmissionController; -use Drupal\webform\Plugin\WebformElementManagerInterface; use Drupal\webform\Utility\WebformArrayHelper; use Drupal\webform\Utility\WebformDialogHelper; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -251,55 +244,26 @@ class WebformSubmissionListBuilder extends EntityListBuilder { * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $entity_type, - $container->get('entity_type.manager')->getStorage($entity_type->id()), - $container->get('entity_type.manager'), - $container->get('current_route_match'), - $container->get('request_stack'), - $container->get('current_user'), - $container->get('config.factory'), - $container->get('webform.request'), - $container->get('plugin.manager.webform.element'), - $container->get('webform.message_manager') - ); + /** @var \Drupal\webform\WebformSubmissionListBuilder $instance */ + $instance = parent::createInstance($container, $entity_type); + + $instance->entityTypeManager = $container->get('entity_type.manager'); + $instance->routeMatch = $container->get('current_route_match'); + $instance->request = $container->get('request_stack')->getCurrentRequest(); + $instance->currentUser = $container->get('current_user'); + $instance->configFactory = $container->get('config.factory'); + $instance->requestHandler = $container->get('webform.request'); + $instance->elementManager = $container->get('plugin.manager.webform.element'); + $instance->messageManager = $container->get('webform.message_manager'); + + $instance->initialize(); + return $instance; } /** - * Constructs a new WebformSubmissionListBuilder object. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type definition. - * @param \Drupal\Core\Entity\EntityStorageInterface $storage - * The entity storage class. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - * @param \Drupal\Core\Routing\RouteMatchInterface $route_match - * The current route match. - * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack - * The request stack. - * @param \Drupal\Core\Session\AccountInterface $current_user - * The current user. - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The configuration factory. - * @param \Drupal\webform\WebformRequestInterface $webform_request - * The webform request handler. - * @param \Drupal\webform\Plugin\WebformElementManagerInterface $element_manager - * The webform element manager. - * @param \Drupal\webform\WebformMessageManagerInterface $message_manager - * The webform message manager. + * Initialize WebformSubmissionListBuilder object. */ - public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, EntityTypeManagerInterface $entity_type_manager, RouteMatchInterface $route_match, RequestStack $request_stack, AccountInterface $current_user, ConfigFactoryInterface $config_factory, WebformRequestInterface $webform_request, WebformElementManagerInterface $element_manager, WebformMessageManagerInterface $message_manager) { - parent::__construct($entity_type, $storage); - $this->entityTypeManager = $entity_type_manager; - $this->routeMatch = $route_match; - $this->request = $request_stack->getCurrentRequest(); - $this->currentUser = $current_user; - $this->configFactory = $config_factory; - $this->requestHandler = $webform_request; - $this->elementManager = $element_manager; - $this->messageManager = $message_manager; - + protected function initialize() { $this->keys = $this->request->query->get('search'); $this->state = $this->request->query->get('state'); $this->sourceEntityTypeId = $this->request->query->get('entity'); diff --git a/src/WebformSubmissionNotesForm.php b/src/WebformSubmissionNotesForm.php index 3dc0b870..fdffdabc 100644 --- a/src/WebformSubmissionNotesForm.php +++ b/src/WebformSubmissionNotesForm.php @@ -3,12 +3,9 @@ namespace Drupal\webform; use Drupal\Core\Entity\ContentEntityForm; -use Drupal\Core\Entity\EntityRepositoryInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\webform\Form\WebformDialogFormTrait; use Symfony\Component\DependencyInjection\ContainerInterface; -use Drupal\Component\Datetime\TimeInterface; -use Drupal\Core\Entity\EntityTypeBundleInfoInterface; /** * Controller for webform submission notes. @@ -24,35 +21,13 @@ class WebformSubmissionNotesForm extends ContentEntityForm { */ protected $requestHandler; - /** - * Constructs a ContentEntityForm object. - * - * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository - * The entity repository. - * @param \Drupal\webform\WebformRequestInterface $webform_request - * The webform request handler. - * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info - * The entity type bundle service. - * @param \Drupal\Component\Datetime\TimeInterface $time - * The time service. - */ - public function __construct(EntityRepositoryInterface $entity_repository, WebformRequestInterface $webform_request, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL) { - // Calling the parent constructor. - parent::__construct($entity_repository, $entity_type_bundle_info, $time); - - $this->requestHandler = $webform_request; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static( - $container->get('entity.repository'), - $container->get('webform.request'), - $container->get('entity_type.bundle.info'), - $container->get('datetime.time') - ); + $instance = parent::create($container); + $instance->requestHandler = $container->get('webform.request'); + return $instance; } /** diff --git a/src/WebformSubmissionStorage.php b/src/WebformSubmissionStorage.php index 7754ddef..56f211f1 100644 --- a/src/WebformSubmissionStorage.php +++ b/src/WebformSubmissionStorage.php @@ -2,22 +2,15 @@ namespace Drupal\webform; -use Drupal\Component\Datetime\TimeInterface; -use Drupal\Core\Cache\CacheBackendInterface; -use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface; -use Drupal\Core\Database\Connection; use Drupal\Core\Database\Query\AlterableInterface; -use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\Query\QueryInterface; -use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Serialization\Yaml; use Drupal\Core\Database\Database; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Sql\SqlContentEntityStorage; use Drupal\Core\Session\AccountInterface; -use Drupal\Core\Session\AccountProxyInterface; use Drupal\Core\StreamWrapper\StreamWrapperInterface; use Drupal\user\Entity\User; use Drupal\user\UserInterface; @@ -57,35 +50,15 @@ class WebformSubmissionStorage extends SqlContentEntityStorage implements Webfor */ protected $accessRulesManager; - /** - * WebformSubmissionStorage constructor. - * - * @todo Webform 8.x-6.x: Move $time before $access_rules_manager. - * @todo Webform 8.x-6.x: Move $memory_cache right after $language_manager. - */ - public function __construct(EntityTypeInterface $entity_type, Connection $database, EntityManagerInterface $entity_manager, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, AccountProxyInterface $current_user, WebformAccessRulesManagerInterface $access_rules_manager, TimeInterface $time = NULL, MemoryCacheInterface $memory_cache = NULL) { - parent::__construct($entity_type, $database, $entity_manager, $cache, $language_manager, $memory_cache); - - $this->currentUser = $current_user; - $this->accessRulesManager = $access_rules_manager; - $this->time = $time ?: \Drupal::time(); - } - /** * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $entity_type, - $container->get('database'), - $container->get('entity.manager'), - $container->get('cache.entity'), - $container->get('language_manager'), - $container->get('current_user'), - $container->get('webform.access_rules_manager'), - $container->get('datetime.time'), - $container->get('entity.memory_cache') - ); + $instance = parent::createInstance($container, $entity_type); + $instance->currentUser = $container->get('current_user'); + $instance->accessRulesManager = $container->get('webform.access_rules_manager'); + $instance->time = $container->get('datetime.time'); + return $instance; } /** diff --git a/src/WebformSubmissionViewBuilder.php b/src/WebformSubmissionViewBuilder.php index b084f6b6..17149f85 100644 --- a/src/WebformSubmissionViewBuilder.php +++ b/src/WebformSubmissionViewBuilder.php @@ -4,12 +4,8 @@ namespace Drupal\webform; use Drupal\Core\Access\AccessResultInterface; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityViewBuilder; -use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\Core\Language\LanguageManagerInterface; -use Drupal\webform\Plugin\WebformElementManagerInterface; use Drupal\webform\Twig\WebformTwigExtension; use Drupal\webform\Utility\WebformElementHelper; use Drupal\webform\Utility\WebformYaml; @@ -48,47 +44,16 @@ class WebformSubmissionViewBuilder extends EntityViewBuilder implements WebformS */ protected $conditionsValidator; - /** - * Constructs a WebformSubmissionViewBuilder. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type definition. - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager service. - * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager - * The language manager. - * @param \Drupal\webform\WebformRequestInterface $webform_request - * The webform request handler. - * @param \Drupal\webform\Plugin\WebformElementManagerInterface $element_manager - * The webform element manager service. - * @param \Drupal\webform\WebformSubmissionConditionsValidatorInterface $conditions_validator - * The webform submission conditions (#states) validator. - * @param \Drupal\Core\Routing\RouteMatchInterface $route_match - * The route match object. - * - * @todo Webform 8.x-6.x: Move $route_match before $webform_request. - */ - public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager, WebformRequestInterface $webform_request, WebformElementManagerInterface $element_manager, WebformSubmissionConditionsValidatorInterface $conditions_validator, RouteMatchInterface $route_match = NULL) { - parent::__construct($entity_type, $entity_manager, $language_manager); - $this->requestHandler = $webform_request; - $this->elementManager = $element_manager; - $this->conditionsValidator = $conditions_validator; - $this->routeMatch = $route_match ?: \Drupal::routeMatch(); - } - /** * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $entity_type, - $container->get('entity.manager'), - $container->get('language_manager'), - $container->get('webform.request'), - $container->get('plugin.manager.webform.element'), - $container->get('webform_submission.conditions_validator'), - $container->get('current_route_match') - ); + $instance = parent::createInstance($container, $entity_type); + $instance->requestHandler = $container->get('webform.request'); + $instance->elementManager = $container->get('plugin.manager.webform.element'); + $instance->conditionsValidator = $container->get('webform_submission.conditions_validator'); + $instance->routeMatch = $container->get('current_route_match'); + return $instance; } /** diff --git a/tests/modules/webform_test_ajax/src/Plugin/Block/WebformTestAjaxBlock.php b/tests/modules/webform_test_ajax/src/Plugin/Block/WebformTestAjaxBlock.php index a2a8ba61..f23e6097 100644 --- a/tests/modules/webform_test_ajax/src/Plugin/Block/WebformTestAjaxBlock.php +++ b/tests/modules/webform_test_ajax/src/Plugin/Block/WebformTestAjaxBlock.php @@ -5,7 +5,6 @@ namespace Drupal\webform_test_ajax\Plugin\Block; use Drupal\Component\Serialization\Json; use Drupal\Core\Block\BlockBase; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\Core\Routing\RedirectDestinationInterface; use Drupal\webform\Entity\Webform; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -27,33 +26,13 @@ class WebformTestAjaxBlock extends BlockBase implements ContainerFactoryPluginIn */ protected $redirectDestination; - /** - * Creates a WebformTestAjaxBlock instance. - * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Drupal\Core\Routing\RedirectDestinationInterface $redirect_destination - * The redirect destination service. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, RedirectDestinationInterface $redirect_destination) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->redirectDestination = $redirect_destination; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('redirect.destination') - ); + $instance = new static($configuration, $plugin_id, $plugin_definition); + $instance->redirectDestination = $container->get('redirect.destination'); + return $instance; } /** diff --git a/tests/src/Unit/Plugin/Block/WebformBlockTest.php b/tests/src/Unit/Plugin/Block/WebformBlockTest.php index 57786ec8..9d9f7ace 100644 --- a/tests/src/Unit/Plugin/Block/WebformBlockTest.php +++ b/tests/src/Unit/Plugin/Block/WebformBlockTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\webform\Unit\Plugin\Block; use Drupal\Core\Access\AccessResult; use Drupal\Core\Cache\Context\CacheContextsManager; +use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Session\AccountInterface; @@ -135,13 +136,19 @@ class WebformBlockTest extends UnitTestCase { ->disableOriginalConstructor() ->getMock(); + // Build container. + $container = new ContainerBuilder(); + $container->set('request_stack', $request_stack); + $container->set('entity_type.manager', $entity_type_manager); + $container->set('webform.token_manager', $token_manager); + $configuration = ['webform_id' => $webform->id()]; $plugin_id = 'webform_block'; $plugin_definition = ['provider' => 'unit_test']; - return new WebformBlock($configuration, $plugin_id, $plugin_definition, $request_stack, $entity_type_manager, $token_manager); + return WebformBlock::create($container, $configuration, $plugin_id, $plugin_definition); } } diff --git a/tests/src/Unit/Plugin/WebformSourceEntity/QueryStringWebformSourceEntityTest.php b/tests/src/Unit/Plugin/WebformSourceEntity/QueryStringWebformSourceEntityTest.php index fceba7fd..168a56b4 100644 --- a/tests/src/Unit/Plugin/WebformSourceEntity/QueryStringWebformSourceEntityTest.php +++ b/tests/src/Unit/Plugin/WebformSourceEntity/QueryStringWebformSourceEntityTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\webform\Unit\Plugin\WebformSourceEntity; +use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; @@ -128,10 +129,18 @@ class QueryStringWebformSourceEntityTest extends UnitTestCase { $language_manager->method('getCurrentLanguage') ->willReturn(new Language(['id' => 'es'])); + // Build container. + $container = new ContainerBuilder(); + $container->set('entity_type.manager', $entity_type_manager); + $container->set('current_route_match', $route_match); + $container->set('request_stack', $request_stack); + $container->set('language_manager', $language_manager); + $container->set('webform.entity_reference_manager', $webform_entity_reference_manager); + /**************************************************************************/ // Create QueryStringWebformSourceEntity plugin instance. - $plugin = new QueryStringWebformSourceEntity([], 'query_string', [], $entity_type_manager, $route_match, $request_stack, $language_manager, $webform_entity_reference_manager); + $plugin = QueryStringWebformSourceEntity::create($container, [], 'query_string', []); $output = $plugin->getSourceEntity($options['ignored_types']); if ($expect_source_entity) { diff --git a/tests/src/Unit/Plugin/WebformSourceEntity/RouteParametersWebformSourceEntityTest.php b/tests/src/Unit/Plugin/WebformSourceEntity/RouteParametersWebformSourceEntityTest.php index 694d336d..0e0351f7 100644 --- a/tests/src/Unit/Plugin/WebformSourceEntity/RouteParametersWebformSourceEntityTest.php +++ b/tests/src/Unit/Plugin/WebformSourceEntity/RouteParametersWebformSourceEntityTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\webform\Unit\Plugin\WebformSourceEntity; +use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\webform\Plugin\WebformSourceEntity\RouteParametersWebformSourceEntity; @@ -57,7 +58,13 @@ class RouteParametersWebformSourceEntityTest extends UnitTestCase { $route_match->method('getParameters') ->willReturn(new ParameterBag($route_parameters)); - $plugin = new RouteParametersWebformSourceEntity([], 'route_parameters', [], $route_match); + // Build container. + $container = new ContainerBuilder(); + $container->set('current_route_match', $route_match); + + /**************************************************************************/ + + $plugin = RouteParametersWebformSourceEntity::create($container, [], 'route_parameters', []); $output = $plugin->getSourceEntity($ignored_types); if ($expect_source_entity) { diff --git a/tests/src/Unit/WebformEntityAccessControlHandlerTest.php b/tests/src/Unit/WebformEntityAccessControlHandlerTest.php index eac7c80a..8cb9eb57 100644 --- a/tests/src/Unit/WebformEntityAccessControlHandlerTest.php +++ b/tests/src/Unit/WebformEntityAccessControlHandlerTest.php @@ -206,10 +206,17 @@ class WebformEntityAccessControlHandlerTest extends UnitTestCase { ) ); + // Build container. + $container = new ContainerBuilder(); + $container->set('request_stack', $request_stack); + $container->set('entity_type.manager', $entity_type_manager); + $container->set('plugin.manager.webform.source_entity', $webform_source_entity_manager); + $container->set('webform.access_rules_manager', $access_rules_manager); + /**************************************************************************/ // Create webform access control handler. - $access_handler = new WebformEntityAccessControlHandler($entity_type, $request_stack, $entity_type_manager, $webform_source_entity_manager, $access_rules_manager); + $access_handler = WebformEntityAccessControlHandler::createInstance($container, $entity_type); // Check access. $access_result = $access_handler->checkAccess($webform, $operation, $account);