contrib modules updates
This commit is contained in:
@@ -2,13 +2,12 @@
|
||||
|
||||
namespace Drupal\ctools\Access;
|
||||
|
||||
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Routing\Access\AccessInterface as CoreAccessInterface;
|
||||
use Drupal\Core\Routing\RouteMatch;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\ctools\Access\AccessInterface as CToolsAccessInterface;
|
||||
use Drupal\user\SharedTempStoreFactory;
|
||||
use Drupal\Core\TempStore\SharedTempStoreFactory;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
class TempstoreAccess implements CoreAccessInterface {
|
||||
@@ -16,7 +15,7 @@ class TempstoreAccess implements CoreAccessInterface {
|
||||
/**
|
||||
* The shared tempstore factory.
|
||||
*
|
||||
* @var \Drupal\user\SharedTempStoreFactory
|
||||
* @var \Drupal\Core\TempStore\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
|
||||
@@ -2,5 +2,4 @@
|
||||
|
||||
namespace Drupal\ctools;
|
||||
|
||||
|
||||
class ContextNotFoundException extends \Exception {}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace Drupal\ctools\Controller;
|
||||
|
||||
use Drupal\Core\Controller\ControllerResolverInterface;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Form\FormBuilderInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\ctools\Wizard\WizardFactoryInterface;
|
||||
@@ -14,11 +14,11 @@ use Drupal\ctools\Wizard\WizardFactoryInterface;
|
||||
class WizardEntityFormController extends WizardFormController {
|
||||
|
||||
/**
|
||||
* The entity manager service.
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* @param \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver
|
||||
@@ -27,12 +27,12 @@ class WizardEntityFormController extends WizardFormController {
|
||||
* The form builder.
|
||||
* @param \Drupal\ctools\Wizard\WizardFactoryInterface $wizard_factory
|
||||
* The wizard factory.
|
||||
* @param \Drupal\Core\Entity\EntityManagerInterface $manager
|
||||
* The entity manager.
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
*/
|
||||
public function __construct(ControllerResolverInterface $controller_resolver, FormBuilderInterface $form_builder, WizardFactoryInterface $wizard_factory, EntityManagerInterface $manager) {
|
||||
public function __construct(ControllerResolverInterface $controller_resolver, FormBuilderInterface $form_builder, WizardFactoryInterface $wizard_factory, EntityTypeManagerInterface $entity_type_manager) {
|
||||
parent::__construct($controller_resolver, $form_builder, $wizard_factory);
|
||||
$this->entityManager = $manager;
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,7 +41,7 @@ class WizardEntityFormController extends WizardFormController {
|
||||
protected function getFormArgument(RouteMatchInterface $route_match) {
|
||||
$form_arg = $route_match->getRouteObject()->getDefault('_entity_wizard');
|
||||
list($entity_type_id, $operation) = explode('.', $form_arg);
|
||||
$definition = $this->entityManager->getDefinition($entity_type_id);
|
||||
$definition = $this->entityTypeManager->getDefinition($entity_type_id);
|
||||
$handlers = $definition->getHandlerClasses();
|
||||
if (empty($handlers['wizard'][$operation])) {
|
||||
throw new \Exception(sprintf('Unsupported wizard operation %s', $operation));
|
||||
|
||||
@@ -6,7 +6,6 @@ use Drupal\Core\Controller\ControllerResolverInterface;
|
||||
use Drupal\Core\Controller\FormController;
|
||||
use Drupal\Core\Form\FormBuilderInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\ctools\Wizard\FormWizardInterface;
|
||||
use Drupal\ctools\Wizard\WizardFactoryInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
@@ -25,7 +24,7 @@ class WizardFormController extends FormController {
|
||||
/**
|
||||
* Tempstore Factory for keeping track of values in each step of the wizard.
|
||||
*
|
||||
* @var \Drupal\user\SharedTempStoreFactory
|
||||
* @var \Drupal\Core\TempStore\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\ctools\Event;
|
||||
|
||||
use Drupal\Core\Block\BlockPluginInterface;
|
||||
use Drupal\ctools\Plugin\BlockVariantInterface;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
class BlockVariantEvent extends Event {
|
||||
|
||||
/**
|
||||
* The block being acted upon.
|
||||
*
|
||||
* @var \Drupal\Core\Block\BlockPluginInterface
|
||||
*/
|
||||
protected $block;
|
||||
|
||||
/**
|
||||
* The variant acting on the block.
|
||||
*
|
||||
* @var \Drupal\ctools\Plugin\BlockVariantInterface
|
||||
*/
|
||||
protected $variant;
|
||||
|
||||
/**
|
||||
* BlockVariantEvent constructor.
|
||||
*
|
||||
* @param \Drupal\Core\Block\BlockPluginInterface $block
|
||||
* The block plugin.
|
||||
* @param \Drupal\ctools\Plugin\BlockVariantInterface $variant
|
||||
* The variant plugin.
|
||||
*/
|
||||
public function __construct(BlockPluginInterface $block, BlockVariantInterface $variant) {
|
||||
$this->block = $block;
|
||||
$this->variant = $variant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the block plugin.
|
||||
*
|
||||
* @return \Drupal\Core\Block\BlockPluginInterface
|
||||
*/
|
||||
public function getBlock() {
|
||||
return $this->block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the variant plugin.
|
||||
*
|
||||
* @return \Drupal\ctools\Plugin\BlockVariantInterface
|
||||
*/
|
||||
public function getVariant() {
|
||||
return $this->variant;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\ctools\Event;
|
||||
|
||||
/**
|
||||
* Contains all events dispatched while manipulating blocks in a variant.
|
||||
*/
|
||||
final class BlockVariantEvents {
|
||||
|
||||
/**
|
||||
* The name of the event triggered when a block is added to a variant.
|
||||
*
|
||||
* This event allows modules to react to a block being added to a variant. The
|
||||
* event listener method receives a \Drupal\ctools\Event\BlockVariantEvent
|
||||
* instance.
|
||||
*
|
||||
* @Event
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const ADD_BLOCK = 'block.add';
|
||||
|
||||
/**
|
||||
* The name of the event triggered when a block is modified in a variant.
|
||||
*
|
||||
* This event allows modules to react to a block being modified in a variant.
|
||||
* The event listener method receives a \Drupal\ctools\Event\BlockVariantEvent
|
||||
* instance.
|
||||
*
|
||||
* @Event
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const UPDATE_BLOCK = 'block.update';
|
||||
|
||||
/**
|
||||
* The name of the event triggered when a block is removed from a variant.
|
||||
*
|
||||
* This event allows modules to react to a block being removed from a variant.
|
||||
* The event listener method receives a \Drupal\ctools\Event\BlockVariantEvent
|
||||
* instance.
|
||||
*
|
||||
* @Event
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const DELETE_BLOCK = 'block.delete';
|
||||
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\ctools\Form;
|
||||
|
||||
|
||||
use Drupal\Component\Plugin\PluginManagerInterface;
|
||||
use Drupal\Component\Uuid\Uuid;
|
||||
use Drupal\Core\Ajax\AjaxResponse;
|
||||
@@ -12,7 +11,8 @@ use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Plugin\ContextAwarePluginInterface;
|
||||
use Drupal\ctools\ConstraintConditionInterface;
|
||||
use Drupal\user\SharedTempStoreFactory;
|
||||
use Drupal\Core\TempStore\SharedTempStoreFactory;
|
||||
use Drupal\Core\Url;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
@@ -21,7 +21,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
abstract class ConditionConfigure extends FormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\user\SharedTempStoreFactory
|
||||
* @var \Drupal\Core\TempStore\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
@@ -44,7 +44,7 @@ abstract class ConditionConfigure extends FormBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static($container->get('user.shared_tempstore'), $container->get('plugin.manager.condition'));
|
||||
return new static($container->get('tempstore.shared'), $container->get('plugin.manager.condition'));
|
||||
}
|
||||
|
||||
function __construct(SharedTempStoreFactory $tempstore, PluginManagerInterface $manager) {
|
||||
@@ -132,7 +132,8 @@ abstract class ConditionConfigure extends FormBase {
|
||||
$response = new AjaxResponse();
|
||||
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
list($route_name, $route_parameters) = $this->getParentRouteInfo($cached_values);
|
||||
$response->addCommand(new RedirectCommand($this->url($route_name, $route_parameters)));
|
||||
$url = Url::fromRoute($route_name, $route_parameters);
|
||||
$response->addCommand(new RedirectCommand($url->toString()));
|
||||
$response->addCommand(new CloseModalDialogCommand());
|
||||
return $response;
|
||||
}
|
||||
|
||||
@@ -8,13 +8,13 @@ use Drupal\Core\Form\ConfirmFormHelper;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\ctools\ConstraintConditionInterface;
|
||||
use Drupal\user\SharedTempStoreFactory;
|
||||
use Drupal\Core\TempStore\SharedTempStoreFactory;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
abstract class ConditionDelete extends ConfirmFormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\user\SharedTempStoreFactory
|
||||
* @var \Drupal\Core\TempStore\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
@@ -42,7 +42,7 @@ abstract class ConditionDelete extends ConfirmFormBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static($container->get('user.shared_tempstore'), $container->get('plugin.manager.condition'));
|
||||
return new static($container->get('tempstore.shared'), $container->get('plugin.manager.condition'));
|
||||
}
|
||||
|
||||
function __construct(SharedTempStoreFactory $tempstore, PluginManagerInterface $manager) {
|
||||
|
||||
@@ -2,11 +2,9 @@
|
||||
|
||||
namespace Drupal\ctools\Form;
|
||||
|
||||
|
||||
use Drupal\Core\Ajax\AjaxResponse;
|
||||
use Drupal\Core\Ajax\CloseModalDialogCommand;
|
||||
use Drupal\Core\Ajax\RedirectCommand;
|
||||
use Drupal\Core\Entity\Entity;
|
||||
use Drupal\Core\Entity\Plugin\DataType\EntityAdapter;
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
@@ -14,23 +12,31 @@ use Drupal\Core\Plugin\Context\Context;
|
||||
use Drupal\Core\Plugin\Context\ContextDefinition;
|
||||
use Drupal\Core\Plugin\Context\ContextInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\user\SharedTempStoreFactory;
|
||||
use Drupal\Core\TempStore\SharedTempStoreFactory;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
|
||||
abstract class ContextConfigure extends FormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\user\SharedTempStoreFactory
|
||||
* @var \Drupal\Core\TempStore\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
/**
|
||||
* Object EntityTypeManager.
|
||||
*
|
||||
* @var Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tempstore_id;
|
||||
|
||||
/**
|
||||
* @var string;
|
||||
* @var string
|
||||
*/
|
||||
protected $machine_name;
|
||||
|
||||
@@ -38,11 +44,15 @@ abstract class ContextConfigure extends FormBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static($container->get('user.shared_tempstore'));
|
||||
return new static(
|
||||
$container->get('tempstore.shared'),
|
||||
$container->get('entity_type.manager')
|
||||
);
|
||||
}
|
||||
|
||||
function __construct(SharedTempStoreFactory $tempstore) {
|
||||
function __construct(SharedTempStoreFactory $tempstore, EntityTypeManagerInterface $entity_type_manager) {
|
||||
$this->tempstore = $tempstore;
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,7 +177,7 @@ abstract class ContextConfigure extends FormBase {
|
||||
if (strpos($context_definition->getDataType(), 'entity:') === 0) {
|
||||
list(, $entity_type) = explode(':', $context_definition->getDataType());
|
||||
if (is_numeric($form_state->getValue('context_value'))) {
|
||||
$value = \Drupal::entityTypeManager()->getStorage($entity_type)->load($form_state->getValue('context_value'));
|
||||
$value = $this->entityTypeManager->getStorage($entity_type)->load($form_state->getValue('context_value'));
|
||||
}
|
||||
}
|
||||
// No loading required for non-entity values.
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
|
||||
namespace Drupal\ctools\Form;
|
||||
|
||||
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Form\ConfirmFormBase;
|
||||
use Drupal\user\SharedTempStoreFactory;
|
||||
use Drupal\Core\TempStore\SharedTempStoreFactory;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
@@ -14,7 +13,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
abstract class ContextDelete extends ConfirmFormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\user\SharedTempStoreFactory
|
||||
* @var \Drupal\Core\TempStore\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
@@ -36,7 +35,7 @@ abstract class ContextDelete extends ConfirmFormBase {
|
||||
protected $context_id;
|
||||
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static($container->get('user.shared_tempstore'));
|
||||
return new static($container->get('tempstore.shared'));
|
||||
}
|
||||
|
||||
public function __construct(SharedTempStoreFactory $tempstore) {
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\ctools\Form;
|
||||
|
||||
|
||||
use Drupal\Component\Plugin\PluginManagerInterface;
|
||||
use Drupal\Component\Serialization\Json;
|
||||
use Drupal\Core\Ajax\AjaxResponse;
|
||||
@@ -12,6 +11,7 @@ use Drupal\Core\Form\FormBuilderInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\Core\Form\FormBuilder;
|
||||
|
||||
abstract class ManageConditions extends FormBase {
|
||||
|
||||
@@ -20,17 +20,28 @@ abstract class ManageConditions extends FormBase {
|
||||
*/
|
||||
protected $manager;
|
||||
|
||||
/**
|
||||
* The builder of form.
|
||||
*
|
||||
* @var \Drupal\Core\Form\FormBuilder
|
||||
*/
|
||||
protected $formBuilder;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $machine_name;
|
||||
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static($container->get('plugin.manager.condition'));
|
||||
return new static(
|
||||
$container->get('plugin.manager.condition'),
|
||||
$container->get('form_builder')
|
||||
);
|
||||
}
|
||||
|
||||
function __construct(PluginManagerInterface $manager) {
|
||||
function __construct(PluginManagerInterface $manager, FormBuilder $form_builder) {
|
||||
$this->manager = $manager;
|
||||
$this->formBuilder = $form_builder;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,11 +102,18 @@ abstract class ManageConditions extends FormBase {
|
||||
|
||||
public function add(array &$form, FormStateInterface $form_state) {
|
||||
$condition = $form_state->getValue('conditions');
|
||||
$content = \Drupal::formBuilder()->getForm($this->getConditionClass(), $condition, $this->getTempstoreId(), $this->machine_name);
|
||||
$content = $this->formBuilder->getForm($this->getConditionClass(), $condition, $this->getTempstoreId(), $this->machine_name);
|
||||
$content['#attached']['library'][] = 'core/drupal.dialog.ajax';
|
||||
$cached_values = $form_state->getTemporaryValue('wizard');
|
||||
list(, $route_parameters) = $this->getOperationsRouteInfo($cached_values, $this->machine_name, $form_state->getValue('conditions'));
|
||||
$content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = $this->url($this->getAddRoute($cached_values), $route_parameters, ['query' => [FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]]);
|
||||
$route_name = $this->getAddRoute($cached_values);
|
||||
$route_options = [
|
||||
'query' => [
|
||||
FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
|
||||
],
|
||||
];
|
||||
$url = Url::fromRoute($route_name, $route_parameters, $route_options);
|
||||
$content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = $url->toString();
|
||||
$response = new AjaxResponse();
|
||||
$response->addCommand(new OpenModalDialogCommand($this->t('Configure Required Context'), $content, array('width' => '700')));
|
||||
return $response;
|
||||
@@ -186,7 +204,7 @@ abstract class ManageConditions extends FormBase {
|
||||
* Document the route name and parameters for edit/delete context operations.
|
||||
*
|
||||
* The route name returned from this method is used as a "base" to which
|
||||
* ".edit" and ".delete" are appeneded in the getOperations() method.
|
||||
* ".edit" and ".delete" are appended in the getOperations() method.
|
||||
* Subclassing '\Drupal\ctools\Form\ConditionConfigure' and
|
||||
* '\Drupal\ctools\Form\ConditionDelete' should set you up for using this
|
||||
* approach quite seamlessly.
|
||||
|
||||
@@ -10,6 +10,7 @@ use Drupal\Core\Form\FormBuilderInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\TypedData\TypedDataManagerInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\ctools\TypedDataResolver;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
abstract class ManageContext extends FormBase {
|
||||
@@ -35,6 +36,13 @@ abstract class ManageContext extends FormBase {
|
||||
*/
|
||||
protected $formBuilder;
|
||||
|
||||
/**
|
||||
* The typed data resolver.
|
||||
*
|
||||
* @var \Drupal\ctools\TypedDataResolver
|
||||
*/
|
||||
protected $typedDataResolver;
|
||||
|
||||
/**
|
||||
* An array of property types that are eligible as relationships.
|
||||
*
|
||||
@@ -49,13 +57,6 @@ abstract class ManageContext extends FormBase {
|
||||
*/
|
||||
protected $relationships = TRUE;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static($container->get('typed_data_manager'), $container->get('form_builder'));
|
||||
}
|
||||
|
||||
/**
|
||||
* ManageContext constructor.
|
||||
*
|
||||
@@ -63,12 +64,25 @@ abstract class ManageContext extends FormBase {
|
||||
* The typed data manager.
|
||||
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
|
||||
* The form builder.
|
||||
* @param \Drupal\ctools\TypedDataResolver $ctools_typed_data_resolver
|
||||
* The typed data resolver.
|
||||
*/
|
||||
public function __construct(TypedDataManagerInterface $typed_data_manager, FormBuilderInterface $form_builder) {
|
||||
public function __construct(TypedDataManagerInterface $typed_data_manager, FormBuilderInterface $form_builder, TypedDataResolver $ctools_typed_data_resolver) {
|
||||
$this->typedDataManager = $typed_data_manager;
|
||||
$this->formBuilder = $form_builder;
|
||||
$this->typedDataResolver = $ctools_typed_data_resolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('typed_data_manager'),
|
||||
$container->get('form_builder'),
|
||||
$container->get('ctools.typed_data.resolver')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@@ -160,7 +174,14 @@ abstract class ManageContext extends FormBase {
|
||||
$content['#attached']['library'][] = 'core/drupal.dialog.ajax';
|
||||
$cached_values = $form_state->getTemporaryValue('wizard');
|
||||
list(, $route_parameters) = $this->getContextOperationsRouteInfo($cached_values, $this->machine_name, $context);
|
||||
$content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = $this->url($this->getContextAddRoute($cached_values), $route_parameters, ['query' => [FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]]);
|
||||
$route_name = $this->getContextAddRoute($cached_values);
|
||||
$route_options = [
|
||||
'query' => [
|
||||
FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
|
||||
],
|
||||
];
|
||||
$url = Url::fromRoute($route_name, $route_parameters, $route_options);
|
||||
$content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = $url->toString();
|
||||
$response = new AjaxResponse();
|
||||
$response->addCommand(new OpenModalDialogCommand($this->t('Add new context'), $content, array('width' => '700')));
|
||||
return $response;
|
||||
@@ -172,7 +193,14 @@ abstract class ManageContext extends FormBase {
|
||||
$content['#attached']['library'][] = 'core/drupal.dialog.ajax';
|
||||
$cached_values = $form_state->getTemporaryValue('wizard');
|
||||
list(, $route_parameters) = $this->getRelationshipOperationsRouteInfo($cached_values, $this->machine_name, $relationship);
|
||||
$content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = $this->url($this->getRelationshipAddRoute($cached_values), $route_parameters, ['query' => [FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]]);
|
||||
$route_name = $this->getRelationshipAddRoute($cached_values);
|
||||
$route_options = [
|
||||
'query' => [
|
||||
FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
|
||||
],
|
||||
];
|
||||
$url = Url::fromRoute($route_name, $route_parameters, $route_options);
|
||||
$content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = $url->toString();
|
||||
$response = new AjaxResponse();
|
||||
$response->addCommand(new OpenModalDialogCommand($this->t('Configure Relationship'), $content, array('width' => '700')));
|
||||
return $response;
|
||||
@@ -180,7 +208,7 @@ abstract class ManageContext extends FormBase {
|
||||
|
||||
protected function getAvailableRelationships($cached_values) {
|
||||
/** @var \Drupal\ctools\TypedDataResolver $resolver */
|
||||
$resolver = \Drupal::service('ctools.typed_data.resolver');
|
||||
$resolver = $this->typedDataResolver;
|
||||
return $resolver->getTokensForContexts($this->getContexts($cached_values));
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormBuilderInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\ctools\TypedDataResolver;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
abstract class ManageResolverRelationships extends FormBase {
|
||||
|
||||
@@ -24,6 +26,43 @@ abstract class ManageResolverRelationships extends FormBase {
|
||||
*/
|
||||
protected $property_types = [];
|
||||
|
||||
/**
|
||||
* The typed data resolver.
|
||||
*
|
||||
* @var \Drupal\ctools\TypedDataResolver
|
||||
*/
|
||||
protected $typedDataResolver;
|
||||
|
||||
/**
|
||||
* The form builder.
|
||||
*
|
||||
* @var \Drupal\Core\Form\FormBuilder
|
||||
*/
|
||||
protected $formBuilder;
|
||||
|
||||
/**
|
||||
* Constructs a new ManageResolverRelationships object.
|
||||
*
|
||||
* @param \Drupal\ctools\TypedDataResolver $ctools_typed_data_resolver
|
||||
* The typed data resolver.
|
||||
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
|
||||
* The form builder.
|
||||
*/
|
||||
public function __construct(TypedDataResolver $ctools_typed_data_resolver, FormBuilderInterface $form_builder) {
|
||||
$this->typedDataResolver = $ctools_typed_data_resolver;
|
||||
$this->formBuilder = $form_builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('ctools.typed_data.resolver'),
|
||||
$container->get('form_builder')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -80,11 +119,18 @@ abstract class ManageResolverRelationships extends FormBase {
|
||||
|
||||
public function addRelationship(array &$form, FormStateInterface $form_state) {
|
||||
$relationship = $form_state->getValue('relationships');
|
||||
$content = \Drupal::formBuilder()->getForm($this->getContextClass(), $relationship, $this->getTempstoreId(), $this->machine_name);
|
||||
$content = $this->formBuilder->getForm($this->getContextClass(), $relationship, $this->getTempstoreId(), $this->machine_name);
|
||||
$content['#attached']['library'][] = 'core/drupal.dialog.ajax';
|
||||
$cached_values = $form_state->getTemporaryValue('wizard');
|
||||
list(, $route_parameters) = $this->getRelationshipOperationsRouteInfo($cached_values, $this->machine_name, $relationship);
|
||||
$content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = $this->url($this->getAddRoute($cached_values), $route_parameters, ['query' => [FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]]);
|
||||
$route_name = $this->getAddRoute($cached_values);
|
||||
$route_options = [
|
||||
'query' => [
|
||||
FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
|
||||
],
|
||||
];
|
||||
$url = Url::fromRoute($route_name, $route_parameters, $route_options);
|
||||
$content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = $url->toString();
|
||||
$response = new AjaxResponse();
|
||||
$response->addCommand(new OpenModalDialogCommand($this->t('Configure Relationship'), $content, array('width' => '700')));
|
||||
return $response;
|
||||
@@ -92,7 +138,7 @@ abstract class ManageResolverRelationships extends FormBase {
|
||||
|
||||
protected function getAvailableRelationships($cached_values) {
|
||||
/** @var \Drupal\ctools\TypedDataResolver $resolver */
|
||||
$resolver = \Drupal::service('ctools.typed_data.resolver');
|
||||
$resolver = $this->typedDataResolver;
|
||||
return $resolver->getTokensForContexts($this->getContexts($cached_values));
|
||||
}
|
||||
|
||||
|
||||
@@ -8,13 +8,14 @@ use Drupal\Core\Ajax\RedirectCommand;
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\ctools\TypedDataResolver;
|
||||
use Drupal\user\SharedTempStoreFactory;
|
||||
use Drupal\Core\TempStore\SharedTempStoreFactory;
|
||||
use Drupal\Core\Url;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
abstract class RelationshipConfigure extends FormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\user\SharedTempStoreFactory
|
||||
* @var \Drupal\Core\TempStore\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
@@ -37,7 +38,7 @@ abstract class RelationshipConfigure extends FormBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static($container->get('user.shared_tempstore'), $container->get('ctools.typed_data.resolver'));
|
||||
return new static($container->get('tempstore.shared'), $container->get('ctools.typed_data.resolver'));
|
||||
}
|
||||
|
||||
public function __construct(SharedTempStoreFactory $tempstore, TypedDataResolver $resolver) {
|
||||
@@ -111,7 +112,8 @@ abstract class RelationshipConfigure extends FormBase {
|
||||
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
list($route_name, $route_parameters) = $this->getParentRouteInfo($cached_values);
|
||||
$response = new AjaxResponse();
|
||||
$response->addCommand(new RedirectCommand($this->url($route_name, $route_parameters)));
|
||||
$url = Url::fromRoute($route_name, $route_parameters);
|
||||
$response->addCommand(new RedirectCommand($url->toString()));
|
||||
$response->addCommand(new CloseModalDialogCommand());
|
||||
return $response;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\Core\Form\FormBuilder;
|
||||
|
||||
abstract class RequiredContext extends FormBase {
|
||||
|
||||
@@ -17,6 +18,13 @@ abstract class RequiredContext extends FormBase {
|
||||
*/
|
||||
protected $typedDataManager;
|
||||
|
||||
/**
|
||||
* The builder of form.
|
||||
*
|
||||
* @var \Drupal\Core\Form\FormBuilder
|
||||
*/
|
||||
protected $formBuilder;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@@ -26,11 +34,15 @@ abstract class RequiredContext extends FormBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static($container->get('typed_data_manager'));
|
||||
return new static(
|
||||
$container->get('typed_data_manager'),
|
||||
$container->get('form_builder')
|
||||
);
|
||||
}
|
||||
|
||||
public function __construct(PluginManagerInterface $typed_data_manager) {
|
||||
public function __construct(PluginManagerInterface $typed_data_manager, FormBuilder $form_builder) {
|
||||
$this->typedDataManager = $typed_data_manager;
|
||||
$this->formBuilder = $form_builder;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,7 +110,7 @@ abstract class RequiredContext extends FormBase {
|
||||
*/
|
||||
public function add(array &$form, FormStateInterface $form_state) {
|
||||
$context = $form_state->getValue('contexts');
|
||||
$content = \Drupal::formBuilder()->getForm($this->getContextClass(), $context, $this->getTempstoreId(), $this->machine_name);
|
||||
$content = $this->formBuilder->getForm($this->getContextClass(), $context, $this->getTempstoreId(), $this->machine_name);
|
||||
$content['#attached']['library'][] = 'core/drupal.dialog.ajax';
|
||||
$response = new AjaxResponse();
|
||||
$response->addCommand(new OpenModalDialogCommand($this->t('Configure Required Context'), $content, array('width' => '700')));
|
||||
@@ -183,7 +195,7 @@ abstract class RequiredContext extends FormBase {
|
||||
* Document the route name and parameters for edit/delete context operations.
|
||||
*
|
||||
* The route name returned from this method is used as a "base" to which
|
||||
* ".edit" and ".delete" are appeneded in the getOperations() method.
|
||||
* ".edit" and ".delete" are appended in the getOperations() method.
|
||||
* Subclassing '\Drupal\ctools\Form\ContextConfigure' and
|
||||
* '\Drupal\ctools\Form\RequiredContextDelete' should set you up for using
|
||||
* this approach quite seamlessly.
|
||||
|
||||
@@ -6,7 +6,7 @@ use Drupal\Core\Form\ConfirmFormBase;
|
||||
use Drupal\Core\Form\ConfirmFormHelper;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\user\SharedTempStoreFactory;
|
||||
use Drupal\Core\TempStore\SharedTempStoreFactory;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
@@ -15,7 +15,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
abstract class RequiredContextDelete extends ConfirmFormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\user\SharedTempStoreFactory
|
||||
* @var \Drupal\Core\TempStore\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
@@ -38,11 +38,11 @@ abstract class RequiredContextDelete extends ConfirmFormBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static($container->get('user.shared_tempstore'));
|
||||
return new static($container->get('tempstore.shared'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Drupal\user\SharedTempStoreFactory $tempstore
|
||||
* @param \Drupal\Core\TempStore\SharedTempStoreFactory $tempstore
|
||||
*/
|
||||
function __construct(SharedTempStoreFactory $tempstore) {
|
||||
$this->tempstore = $tempstore;
|
||||
|
||||
@@ -2,19 +2,19 @@
|
||||
|
||||
namespace Drupal\ctools\Form;
|
||||
|
||||
|
||||
use Drupal\Core\Ajax\AjaxResponse;
|
||||
use Drupal\Core\Ajax\CloseModalDialogCommand;
|
||||
use Drupal\Core\Ajax\RedirectCommand;
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\user\SharedTempStoreFactory;
|
||||
use Drupal\Core\TempStore\SharedTempStoreFactory;
|
||||
use Drupal\Core\Url;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
abstract class ResolverRelationshipConfigure extends FormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\user\SharedTempStoreFactory
|
||||
* @var \Drupal\Core\TempStore\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
@@ -32,7 +32,7 @@ abstract class ResolverRelationshipConfigure extends FormBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static($container->get('user.shared_tempstore'));
|
||||
return new static($container->get('tempstore.shared'));
|
||||
}
|
||||
|
||||
function __construct(SharedTempStoreFactory $tempstore) {
|
||||
@@ -141,7 +141,8 @@ abstract class ResolverRelationshipConfigure extends FormBase {
|
||||
$response = new AjaxResponse();
|
||||
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
list($route_name, $route_parameters) = $this->getParentRouteInfo($cached_values);
|
||||
$response->addCommand(new RedirectCommand($this->url($route_name, $route_parameters)));
|
||||
$url = Url::fromRoute($route_name, $route_parameters);
|
||||
$response->addCommand(new RedirectCommand($url->toString()));
|
||||
$response->addCommand(new CloseModalDialogCommand());
|
||||
return $response;
|
||||
}
|
||||
|
||||
@@ -2,18 +2,17 @@
|
||||
|
||||
namespace Drupal\ctools\Form;
|
||||
|
||||
|
||||
use Drupal\Core\Form\ConfirmFormBase;
|
||||
use Drupal\Core\Form\ConfirmFormHelper;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\ctools\TypedDataResolver;
|
||||
use Drupal\user\SharedTempStoreFactory;
|
||||
use Drupal\Core\TempStore\SharedTempStoreFactory;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
abstract class ResolverRelationshipDelete extends ConfirmFormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\user\SharedTempStoreFactory
|
||||
* @var \Drupal\Core\TempStore\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
@@ -41,14 +40,14 @@ abstract class ResolverRelationshipDelete extends ConfirmFormBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static($container->get('user.shared_tempstore'), $container->get('ctools.typed_data.resolver'));
|
||||
return new static($container->get('tempstore.shared'), $container->get('ctools.typed_data.resolver'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Drupal\user\SharedTempStoreFactory $tempstore
|
||||
* @param \Drupal\Core\TempStore\SharedTempStoreFactory $tempstore
|
||||
* The shared tempstore.
|
||||
* @param \Drupal\ctools\TypedDataResolver $resolver
|
||||
* The the typed data resolver.
|
||||
* The typed data resolver.
|
||||
*/
|
||||
public function __construct(SharedTempStoreFactory $tempstore, TypedDataResolver $resolver) {
|
||||
$this->tempstore = $tempstore;
|
||||
|
||||
@@ -3,10 +3,9 @@
|
||||
namespace Drupal\ctools\ParamConverter;
|
||||
|
||||
use Drupal\Component\Utility\NestedArray;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\ParamConverter\ParamConverterInterface;
|
||||
use Drupal\user\SharedTempStoreFactory;
|
||||
use Drupal\Core\TempStore\SharedTempStoreFactory;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
@@ -83,7 +82,7 @@ class TempstoreConverter implements ParamConverterInterface {
|
||||
/**
|
||||
* The tempstore factory.
|
||||
*
|
||||
* @var \Drupal\user\SharedTempStoreFactory
|
||||
* @var \Drupal\Core\TempStore\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
@@ -97,7 +96,7 @@ class TempstoreConverter implements ParamConverterInterface {
|
||||
/**
|
||||
* Constructs a TempstoreConverter.
|
||||
*
|
||||
* @param \Drupal\user\SharedTempStoreFactory $tempstore
|
||||
* @param \Drupal\Core\TempStore\SharedTempStoreFactory $tempstore
|
||||
*/
|
||||
public function __construct(SharedTempStoreFactory $tempstore, EntityTypeManagerInterface $entity_type_manager) {
|
||||
$this->tempstore = $tempstore;
|
||||
|
||||
@@ -4,7 +4,8 @@ namespace Drupal\ctools\Plugin\Block;
|
||||
|
||||
use Drupal\Core\Block\BlockBase;
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Entity\EntityDisplayRepositoryInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\Core\Plugin\ContextAwarePluginInterface;
|
||||
@@ -21,11 +22,18 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
class EntityView extends BlockBase implements ContextAwarePluginInterface, ContainerFactoryPluginInterface {
|
||||
|
||||
/**
|
||||
* The entity manager.
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The entity display repository.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
|
||||
*/
|
||||
protected $entityDisplayRepository;
|
||||
|
||||
/**
|
||||
* Constructs a new EntityView.
|
||||
@@ -36,13 +44,16 @@ class EntityView extends BlockBase implements ContextAwarePluginInterface, Conta
|
||||
* The plugin ID for the plugin instance.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin implementation definition.
|
||||
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
|
||||
* The entity manager.
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
* @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
|
||||
* The entity display repository.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager) {
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
|
||||
$this->entityManager = $entity_manager;
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
$this->entityDisplayRepository = $entity_display_repository;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +64,8 @@ class EntityView extends BlockBase implements ContextAwarePluginInterface, Conta
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('entity.manager')
|
||||
$container->get('entity_type.manager'),
|
||||
$container->get('entity_display.repository')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -72,7 +84,7 @@ class EntityView extends BlockBase implements ContextAwarePluginInterface, Conta
|
||||
public function blockForm($form, FormStateInterface $form_state) {
|
||||
$form['view_mode'] = [
|
||||
'#type' => 'select',
|
||||
'#options' => $this->entityManager->getViewModeOptions($this->getDerivativeId()),
|
||||
'#options' => $this->entityDisplayRepository->getViewModeOptions($this->getDerivativeId()),
|
||||
'#title' => $this->t('View mode'),
|
||||
'#default_value' => $this->configuration['view_mode'],
|
||||
];
|
||||
@@ -93,7 +105,7 @@ class EntityView extends BlockBase implements ContextAwarePluginInterface, Conta
|
||||
/** @var $entity \Drupal\Core\Entity\EntityInterface */
|
||||
$entity = $this->getContextValue('entity');
|
||||
|
||||
$view_builder = $this->entityManager->getViewBuilder($entity->getEntityTypeId());
|
||||
$view_builder = $this->entityTypeManager->getViewBuilder($entity->getEntityTypeId());
|
||||
$build = $view_builder->view($entity, $this->configuration['view_mode']);
|
||||
|
||||
CacheableMetadata::createFromObject($this->getContext('entity'))
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace Drupal\ctools\Plugin;
|
||||
|
||||
use Drupal\ctools\Event\BlockVariantEvent;
|
||||
use Drupal\ctools\Event\BlockVariantEvents;
|
||||
|
||||
/**
|
||||
* Provides methods for \Drupal\ctools\Plugin\BlockVariantInterface.
|
||||
*/
|
||||
@@ -21,6 +24,13 @@ trait BlockVariantTrait {
|
||||
*/
|
||||
protected $blockPluginCollection;
|
||||
|
||||
/**
|
||||
* The event dispatcher.
|
||||
*
|
||||
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
|
||||
*/
|
||||
protected $eventDispatcher;
|
||||
|
||||
/**
|
||||
* @see \Drupal\ctools\Plugin\BlockVariantInterface::getRegionNames()
|
||||
*/
|
||||
@@ -39,6 +49,12 @@ trait BlockVariantTrait {
|
||||
public function addBlock(array $configuration) {
|
||||
$configuration['uuid'] = $this->uuidGenerator()->generate();
|
||||
$this->getBlockCollection()->addInstanceId($configuration['uuid'], $configuration);
|
||||
|
||||
$block = $this->getBlock($configuration['uuid']);
|
||||
// Allow modules to react to the change.
|
||||
$event = new BlockVariantEvent($block, $this);
|
||||
$this->eventDispatcher()->dispatch(BlockVariantEvents::ADD_BLOCK, $event);
|
||||
|
||||
return $configuration['uuid'];
|
||||
}
|
||||
|
||||
@@ -46,7 +62,13 @@ trait BlockVariantTrait {
|
||||
* @see \Drupal\ctools\Plugin\BlockVariantInterface::removeBlock()
|
||||
*/
|
||||
public function removeBlock($block_id) {
|
||||
$block = $this->getBlock($block_id);
|
||||
$this->getBlockCollection()->removeInstanceId($block_id);
|
||||
|
||||
// Allow modules to react to the change.
|
||||
$event = new BlockVariantEvent($block, $this);
|
||||
$this->eventDispatcher()->dispatch(BlockVariantEvents::DELETE_BLOCK, $event);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -54,8 +76,14 @@ trait BlockVariantTrait {
|
||||
* @see \Drupal\ctools\Plugin\BlockVariantInterface::updateBlock()
|
||||
*/
|
||||
public function updateBlock($block_id, array $configuration) {
|
||||
$existing_configuration = $this->getBlock($block_id)->getConfiguration();
|
||||
$block = $this->getBlock($block_id);
|
||||
$existing_configuration = $block->getConfiguration();
|
||||
$this->getBlockCollection()->setInstanceConfiguration($block_id, $configuration + $existing_configuration);
|
||||
|
||||
// Allow modules to react to the change.
|
||||
$event = new BlockVariantEvent($block, $this);
|
||||
$this->eventDispatcher()->dispatch(BlockVariantEvents::UPDATE_BLOCK, $event);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -112,6 +140,18 @@ trait BlockVariantTrait {
|
||||
return $this->blockPluginCollection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the event dispatcher.
|
||||
*
|
||||
* @return \Symfony\Component\EventDispatcher\EventDispatcherInterface
|
||||
*/
|
||||
protected function eventDispatcher() {
|
||||
if (!$this->eventDispatcher) {
|
||||
$this->eventDispatcher = \Drupal::service('event_dispatcher');
|
||||
}
|
||||
return $this->eventDispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the UUID generator.
|
||||
*
|
||||
|
||||
@@ -13,7 +13,7 @@ class EntityBundle extends EntityDeriverBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDerivativeDefinitions($base_plugin_definition) {
|
||||
foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
|
||||
foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
|
||||
if ($entity_type->hasKey('bundle')) {
|
||||
$this->derivatives[$entity_type_id] = $base_plugin_definition;
|
||||
$this->derivatives[$entity_type_id]['label'] = $this->getEntityBundleLabel($entity_type);
|
||||
@@ -43,7 +43,7 @@ class EntityBundle extends EntityDeriverBase {
|
||||
$fallback = $entity_type->getLabel();
|
||||
if ($bundle_entity_type = $entity_type->getBundleEntityType()) {
|
||||
// This is a better fallback.
|
||||
$fallback = $this->entityManager->getDefinition($bundle_entity_type)->getLabel();
|
||||
$fallback = $this->entityTypeManager->getDefinition($bundle_entity_type)->getLabel();
|
||||
}
|
||||
|
||||
return $this->t('@label bundle', ['@label' => $fallback]);
|
||||
|
||||
@@ -4,7 +4,9 @@ namespace Drupal\ctools\Plugin\Deriver;
|
||||
|
||||
|
||||
use Drupal\Component\Plugin\Derivative\DeriverBase;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Entity\EntityFieldManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeRepositoryInterface;
|
||||
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Drupal\Core\StringTranslation\TranslationInterface;
|
||||
@@ -18,23 +20,43 @@ abstract class EntityDeriverBase extends DeriverBase implements ContainerDeriver
|
||||
use StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* The entity manager.
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The entity field manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
|
||||
*/
|
||||
protected $entityFieldManager;
|
||||
|
||||
/**
|
||||
* The entity type repository.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeRepositoryInterface
|
||||
*/
|
||||
protected $entityTypeRepository;
|
||||
|
||||
/**
|
||||
* Constructs new EntityViewDeriver.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
|
||||
* The entity manager.
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
|
||||
* The string translation service.
|
||||
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
|
||||
* The entity field manager.
|
||||
* @param \Drupal\Core\Entity\EntityTypeRepositoryInterface $entity_type_repository
|
||||
* The entity type repository.
|
||||
*/
|
||||
public function __construct(EntityManagerInterface $entity_manager, TranslationInterface $string_translation) {
|
||||
$this->entityManager = $entity_manager;
|
||||
public function __construct(EntityTypeManagerInterface $entity_type_manager, TranslationInterface $string_translation, EntityFieldManagerInterface $entity_field_manager, EntityTypeRepositoryInterface $entity_type_repository) {
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
$this->stringTranslation = $string_translation;
|
||||
$this->entityFieldManager = $entity_field_manager;
|
||||
$this->entityTypeRepository = $entity_type_repository;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,8 +64,10 @@ abstract class EntityDeriverBase extends DeriverBase implements ContainerDeriver
|
||||
*/
|
||||
public static function create(ContainerInterface $container, $base_plugin_id) {
|
||||
return new static(
|
||||
$container->get('entity.manager'),
|
||||
$container->get('string_translation')
|
||||
$container->get('entity_type.manager'),
|
||||
$container->get('string_translation'),
|
||||
$container->get('entity_field.manager'),
|
||||
$container->get('entity_type.repository')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class EntityViewDeriver extends EntityDeriverBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDerivativeDefinitions($base_plugin_definition) {
|
||||
foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
|
||||
foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
|
||||
if ($entity_type->hasViewBuilderClass()) {
|
||||
$this->derivatives[$entity_type_id] = $base_plugin_definition;
|
||||
$this->derivatives[$entity_type_id]['admin_label'] = $this->t('Entity view (@label)', ['@label' => $entity_type->getLabel()]);
|
||||
|
||||
+1
-3
@@ -4,13 +4,11 @@ namespace Drupal\ctools\Plugin\DisplayVariant;
|
||||
|
||||
use Drupal\Component\Uuid\UuidInterface;
|
||||
use Drupal\Core\Block\BlockManager;
|
||||
use Drupal\Core\Cache\RefinableCacheableDependencyInterface;
|
||||
use Drupal\Core\Condition\ConditionManager;
|
||||
use Drupal\Core\Display\VariantBase;
|
||||
use Drupal\Core\Display\ContextAwareVariantInterface;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\Core\Plugin\Context\ContextHandlerInterface;
|
||||
use Drupal\Core\Render\Element;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Utility\Token;
|
||||
use Drupal\ctools\Form\AjaxFormTrait;
|
||||
@@ -21,7 +19,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
/**
|
||||
* Provides a base class for a display variant that simply contains blocks.
|
||||
*/
|
||||
abstract class BlockDisplayVariant extends VariantBase implements ContextAwareVariantInterface, ContainerFactoryPluginInterface, BlockVariantInterface, RefinableCacheableDependencyInterface {
|
||||
abstract class BlockDisplayVariant extends VariantBase implements ContextAwareVariantInterface, ContainerFactoryPluginInterface, BlockVariantInterface {
|
||||
|
||||
use AjaxFormTrait;
|
||||
use BlockVariantTrait;
|
||||
|
||||
+1
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin\Relationship;
|
||||
|
||||
use Drupal\Core\Plugin\Context\Context;
|
||||
use Drupal\Core\Plugin\Context\ContextDefinition;
|
||||
|
||||
|
||||
+1
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin\Relationship;
|
||||
|
||||
use Drupal\Core\Plugin\Context\Context;
|
||||
use Drupal\Core\Plugin\Context\ContextDefinition;
|
||||
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
|
||||
namespace Drupal\ctools\Plugin\Relationship;
|
||||
|
||||
|
||||
use Drupal\Core\Field\FieldItemInterface;
|
||||
use Drupal\Core\Field\TypedData\FieldItemDataDefinition;
|
||||
use Drupal\Core\Plugin\Context\Context;
|
||||
use Drupal\Core\Plugin\Context\ContextDefinition;
|
||||
use Drupal\Core\Plugin\Context\ContextInterface;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin;
|
||||
|
||||
use Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface;
|
||||
use Drupal\Core\Plugin\Context\ContextAwarePluginManagerInterface;
|
||||
|
||||
|
||||
@@ -2,33 +2,46 @@
|
||||
|
||||
namespace Drupal\ctools\Routing\Enhancer;
|
||||
|
||||
use Drupal\Core\Routing\Enhancer\RouteEnhancerInterface;
|
||||
use Drupal\Core\Routing\EnhancerInterface;
|
||||
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* Sets the request format onto the request object.
|
||||
*/
|
||||
class WizardEnhancer implements RouteEnhancerInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function applies(Route $route) {
|
||||
return !$route->hasDefault('_controller') && ($route->hasDefault('_wizard') || $route->hasDefault('_entity_wizard'));
|
||||
}
|
||||
class WizardEnhancer implements EnhancerInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function enhance(array $defaults, Request $request) {
|
||||
$route = $defaults[RouteObjectInterface::ROUTE_OBJECT];
|
||||
if (!$this->isApplicable($route)) {
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
if (!empty($defaults['_wizard'])) {
|
||||
$defaults['_controller'] = 'ctools.wizard.form:getContentResult';
|
||||
}
|
||||
if (!empty($defaults['_entity_wizard'])) {
|
||||
$defaults['_controller'] = 'ctools.wizard.entity.form:getContentResult';
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if current route use ctools default parameters.
|
||||
*
|
||||
* @param \Symfony\Component\Routing\Route $route
|
||||
* The route to check.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the route use one of ctools route default parameters or FALSE.
|
||||
*/
|
||||
public function isApplicable(Route $route) {
|
||||
return !$route->hasDefault('_controller') && ($route->hasDefault('_wizard') || $route->hasDefault('_entity_wizard'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace Drupal\ctools;
|
||||
|
||||
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
|
||||
use Drupal\user\SharedTempStore;
|
||||
use Drupal\Core\TempStore\SharedTempStore;
|
||||
|
||||
/**
|
||||
* An extension of the SharedTempStore system for serialized data.
|
||||
|
||||
@@ -2,25 +2,55 @@
|
||||
|
||||
namespace Drupal\ctools;
|
||||
|
||||
use Drupal\user\SharedTempStoreFactory;
|
||||
use Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface;
|
||||
use Drupal\Core\Lock\LockBackendInterface;
|
||||
use Drupal\Core\Session\AccountProxyInterface;
|
||||
use Drupal\Core\TempStore\SharedTempStoreFactory;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
/**
|
||||
* A factory for creating SerializableTempStore objects.
|
||||
*/
|
||||
class SerializableTempstoreFactory extends SharedTempStoreFactory {
|
||||
|
||||
/**
|
||||
* The current logged user.
|
||||
*
|
||||
* @var \Drupal\Core\Session\AccountProxyInterface
|
||||
*/
|
||||
protected $currentUser;
|
||||
|
||||
/**
|
||||
* Constructs a Drupal\Core\TempStore\SharedTempStoreFactory object.
|
||||
*
|
||||
* @param \Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface $storage_factory
|
||||
* The key/value store factory.
|
||||
* @param \Drupal\Core\Lock\LockBackendInterface $lock_backend
|
||||
* The lock object used for this data.
|
||||
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
|
||||
* The request stack.
|
||||
* @param int $expire
|
||||
* The time to live for items, in seconds.
|
||||
* @param \Drupal\Core\Session\AccountProxyInterface|null $current_user
|
||||
* The current logged user.
|
||||
*/
|
||||
public function __construct(KeyValueExpirableFactoryInterface $storage_factory, LockBackendInterface $lock_backend, RequestStack $request_stack, $expire = 604800, AccountProxyInterface $current_user = NULL) {
|
||||
parent::__construct($storage_factory, $lock_backend, $request_stack, $expire);
|
||||
$this->currentUser = $current_user ?: \Drupal::currentUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function get($collection, $owner = NULL) {
|
||||
public function get($collection, $owner = NULL) {
|
||||
// Use the currently authenticated user ID or the active user ID unless the
|
||||
// owner is overridden.
|
||||
if (!isset($owner)) {
|
||||
$owner = \Drupal::currentUser()->id() ?: session_id();
|
||||
$owner = $this->currentUser->id() ?: session_id();
|
||||
}
|
||||
|
||||
// Store the data for this collection in the database.
|
||||
$storage = $this->storageFactory->get("user.shared_tempstore.$collection");
|
||||
$storage = $this->storageFactory->get("tempstore.shared.$collection");
|
||||
return new SerializableTempstore($storage, $this->lockBackend, $owner, $this->requestStack, $this->expire);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\ctools\Testing;
|
||||
|
||||
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
|
||||
trait EntityCreationTrait {
|
||||
|
||||
@@ -1,43 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\ctools\Tests\Wizard;
|
||||
namespace Drupal\Tests\ctools\Functional;
|
||||
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests basic wizard functionality.
|
||||
*
|
||||
* @group ctools
|
||||
*/
|
||||
class CToolsWizardTest extends WebTestBase {
|
||||
class CToolsWizardTest extends BrowserTestBase {
|
||||
|
||||
use StringTranslationTrait;
|
||||
public static $modules = array('ctools', 'ctools_wizard_test');
|
||||
public static $modules = ['ctools', 'ctools_wizard_test'];
|
||||
|
||||
function testWizardSteps() {
|
||||
/**
|
||||
* Test wizard Multistep form.
|
||||
*/
|
||||
public function testWizardSteps() {
|
||||
$this->drupalGet('ctools/wizard');
|
||||
$this->assertText('Form One');
|
||||
$this->assertSession()->pageTextContains('Form One');
|
||||
$this->dumpHeaders = TRUE;
|
||||
// Check that $operations['one']['values'] worked.
|
||||
$this->assertText('Xylophone');
|
||||
$this->assertSession()->pageTextContains('Xylophone');
|
||||
// Submit first step in the wizard.
|
||||
$edit = [
|
||||
'one' => 'test',
|
||||
];
|
||||
$this->drupalPostForm('ctools/wizard', $edit, $this->t('Next'));
|
||||
// Redirected to the second step.
|
||||
$this->assertText('Form Two');
|
||||
$this->assertText('Dynamic value submitted: Xylophone');
|
||||
$this->assertSession()->pageTextContains('Form Two');
|
||||
$this->assertSession()->pageTextContains('Dynamic value submitted: Xylophone');
|
||||
// Check that $operations['two']['values'] worked.
|
||||
$this->assertText('Zebra');
|
||||
$this->assertSession()->pageTextContains('Zebra');
|
||||
// Hit previous to make sure our form value are preserved.
|
||||
$this->drupalPostForm(NULL, [], $this->t('Previous'));
|
||||
// Check the known form values.
|
||||
$this->assertFieldByName('one', 'test');
|
||||
$this->assertText('Xylophone');
|
||||
$this->assertSession()->fieldValueEquals('one', 'test');
|
||||
$this->assertSession()->pageTextContains('Xylophone');
|
||||
// Goto next step again and finish this wizard.
|
||||
$this->drupalPostForm(NULL, [], $this->t('Next'));
|
||||
$edit = [
|
||||
@@ -45,44 +46,50 @@ class CToolsWizardTest extends WebTestBase {
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, $this->t('Finish'));
|
||||
// Check that the wizard finished properly.
|
||||
$this->assertText('Value One: test');
|
||||
$this->assertText('Value Two: Second test');
|
||||
$this->assertSession()->pageTextContains('Value One: test');
|
||||
$this->assertSession()->pageTextContains('Value Two: Second test');
|
||||
}
|
||||
|
||||
function testStepValidateAndSubmit() {
|
||||
/**
|
||||
* Test wizard validate and submit.
|
||||
*/
|
||||
public function testStepValidateAndSubmit() {
|
||||
$this->drupalGet('ctools/wizard');
|
||||
$this->assertText('Form One');
|
||||
$this->assertSession()->pageTextContains('Form One');
|
||||
// Submit first step in the wizard.
|
||||
$edit = [
|
||||
'one' => 'wrong',
|
||||
];
|
||||
$this->drupalPostForm('ctools/wizard', $edit, $this->t('Next'));
|
||||
// We're still on the first form and the error is present.
|
||||
$this->assertText('Form One');
|
||||
$this->assertText('Cannot set the value to "wrong".');
|
||||
$this->assertSession()->pageTextContains('Form One');
|
||||
$this->assertSession()->pageTextContains('Cannot set the value to "wrong".');
|
||||
// Try again with the magic value.
|
||||
$edit = [
|
||||
'one' => 'magic',
|
||||
];
|
||||
$this->drupalPostForm('ctools/wizard', $edit, $this->t('Next'));
|
||||
// Redirected to the second step.
|
||||
$this->assertText('Form Two');
|
||||
$this->assertSession()->pageTextContains('Form Two');
|
||||
$edit = [
|
||||
'two' => 'Second test',
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, $this->t('Finish'));
|
||||
// Check that the magic value triggered our submit callback.
|
||||
$this->assertText('Value One: Abraham');
|
||||
$this->assertText('Value Two: Second test');
|
||||
$this->assertSession()->pageTextContains('Value One: Abraham');
|
||||
$this->assertSession()->pageTextContains('Value Two: Second test');
|
||||
}
|
||||
|
||||
function testEntityWizard() {
|
||||
/**
|
||||
* Test wizard entity config update.
|
||||
*/
|
||||
public function testEntityWizard() {
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer site configuration']));
|
||||
|
||||
// Start adding a new config entity.
|
||||
$this->drupalGet('admin/structure/ctools_wizard_test_config_entity/add');
|
||||
$this->assertText('Example entity');
|
||||
$this->assertNoText('Existing entity');
|
||||
$this->assertSession()->pageTextContains('Example entity');
|
||||
$this->assertSession()->pageTextNotContains('Existing entity');
|
||||
|
||||
// Submit the general step.
|
||||
$edit = [
|
||||
@@ -104,33 +111,32 @@ class CToolsWizardTest extends WebTestBase {
|
||||
$this->drupalPostForm(NULL, $edit, $this->t('Finish'));
|
||||
|
||||
// Now we should be looking at the list of entities.
|
||||
$this->assertUrl('admin/structure/ctools_wizard_test_config_entity');
|
||||
$this->assertText('Test Config Entity 123');
|
||||
$this->assertSession()->addressEquals('admin/structure/ctools_wizard_test_config_entity');
|
||||
$this->assertSession()->pageTextContains('Test Config Entity 123');
|
||||
|
||||
// Edit the entity again and make sure the values are what we expect.
|
||||
$this->clickLink(t('Edit'));
|
||||
$this->assertText('Existing entity');
|
||||
$this->assertFieldByName('label', 'Test Config Entity 123');
|
||||
$this->assertSession()->pageTextContains('Existing entity');
|
||||
$this->assertSession()->fieldValueEquals('label', 'Test Config Entity 123');
|
||||
$this->clickLink(t('Form One'));
|
||||
$this->assertFieldByName('one', 'The first bit');
|
||||
$this->assertSession()->fieldValueEquals('one', 'The first bit');
|
||||
$previous = $this->getUrl();
|
||||
$this->clickLink(t('Show on dialog'));
|
||||
$this->assertRaw('Value from one: The first bit');
|
||||
$this->assertSession()->responseContains('Value from one: The first bit');
|
||||
$this->drupalGet($previous);
|
||||
// Change the value for 'one'.
|
||||
$this->drupalPostForm(NULL, ['one' => 'New value'], $this->t('Next'));
|
||||
$this->assertFieldByName('two', 'The second bit');
|
||||
$this->assertSession()->fieldValueEquals('two', 'The second bit');
|
||||
$this->drupalPostForm(NULL, [], $this->t('Next'));
|
||||
// Make sure we get the additional step because the entity exists.
|
||||
$this->assertText('This step only shows if the entity is already existing!');
|
||||
$this->assertSession()->pageTextContains('This step only shows if the entity is already existing!');
|
||||
$this->drupalPostForm(NULL, [], $this->t('Finish'));
|
||||
|
||||
// Edit the entity again and make sure the change stuck.
|
||||
$this->assertUrl('admin/structure/ctools_wizard_test_config_entity');
|
||||
$this->assertSession()->addressEquals('admin/structure/ctools_wizard_test_config_entity');
|
||||
$this->clickLink(t('Edit'));
|
||||
$this->drupalPostForm(NULL, [], $this->t('Next'));
|
||||
$this->assertFieldByName('one', 'New value');
|
||||
$this->clickLink(t('Form One'));
|
||||
$this->assertSession()->fieldValueEquals('one', 'New value');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,8 @@
|
||||
|
||||
namespace Drupal\ctools;
|
||||
|
||||
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\Core\Plugin\Context\Context;
|
||||
use Drupal\Core\Plugin\Context\ContextDefinition;
|
||||
use Drupal\Core\Plugin\Context\ContextDefinitionInterface;
|
||||
use Drupal\Core\Plugin\Context\ContextInterface;
|
||||
use Drupal\Core\StringTranslation\TranslationInterface;
|
||||
use Drupal\Core\TypedData\ComplexDataDefinitionInterface;
|
||||
|
||||
@@ -2,14 +2,13 @@
|
||||
|
||||
namespace Drupal\ctools\Wizard;
|
||||
|
||||
|
||||
use Drupal\Core\DependencyInjection\ClassResolverInterface;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Form\FormBuilderInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\ctools\Event\WizardEvent;
|
||||
use Drupal\user\SharedTempStoreFactory;
|
||||
use Drupal\Core\TempStore\SharedTempStoreFactory;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
/**
|
||||
@@ -18,14 +17,14 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
abstract class EntityFormWizardBase extends FormWizardBase implements EntityFormWizardInterface {
|
||||
|
||||
/**
|
||||
* The entity manager.
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* @param \Drupal\user\SharedTempStoreFactory $tempstore
|
||||
* @param \Drupal\Core\TempStore\SharedTempStoreFactory $tempstore
|
||||
* Tempstore Factory for keeping track of values in each step of the
|
||||
* wizard.
|
||||
* @param \Drupal\Core\Form\FormBuilderInterface $builder
|
||||
@@ -34,8 +33,8 @@ abstract class EntityFormWizardBase extends FormWizardBase implements EntityForm
|
||||
* The class resolver.
|
||||
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
|
||||
* The event dispatcher.
|
||||
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
|
||||
* The entity manager.
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
* @param $tempstore_id
|
||||
* The shared temp store factory collection name.
|
||||
* @param null $machine_name
|
||||
@@ -43,8 +42,8 @@ abstract class EntityFormWizardBase extends FormWizardBase implements EntityForm
|
||||
* @param null $step
|
||||
* The current active step of the wizard.
|
||||
*/
|
||||
public function __construct(SharedTempStoreFactory $tempstore, FormBuilderInterface $builder, ClassResolverInterface $class_resolver, EventDispatcherInterface $event_dispatcher, EntityManagerInterface $entity_manager, RouteMatchInterface $route_match, $tempstore_id, $machine_name = NULL, $step = NULL) {
|
||||
$this->entityManager = $entity_manager;
|
||||
public function __construct(SharedTempStoreFactory $tempstore, FormBuilderInterface $builder, ClassResolverInterface $class_resolver, EventDispatcherInterface $event_dispatcher, EntityTypeManagerInterface $entity_type_manager, RouteMatchInterface $route_match, $tempstore_id, $machine_name = NULL, $step = NULL) {
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
parent::__construct($tempstore, $builder, $class_resolver, $event_dispatcher, $route_match, $tempstore_id, $machine_name, $step);
|
||||
}
|
||||
|
||||
@@ -53,11 +52,14 @@ abstract class EntityFormWizardBase extends FormWizardBase implements EntityForm
|
||||
*/
|
||||
public static function getParameters() {
|
||||
return [
|
||||
'tempstore' => \Drupal::service('user.shared_tempstore'),
|
||||
'tempstore' => \Drupal::service('tempstore.shared'),
|
||||
'builder' => \Drupal::service('form_builder'),
|
||||
'class_resolver' => \Drupal::service('class_resolver'),
|
||||
'event_dispatcher' => \Drupal::service('event_dispatcher'),
|
||||
// Keep the deprecated entity manager service as a parameter as well for
|
||||
// BC, so that subclasses still work.
|
||||
'entity_manager' => \Drupal::service('entity.manager'),
|
||||
'entity_type_manager' => \Drupal::service('entity_type.manager'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -65,7 +67,7 @@ abstract class EntityFormWizardBase extends FormWizardBase implements EntityForm
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function initValues() {
|
||||
$storage = $this->entityManager->getStorage($this->getEntityType());
|
||||
$storage = $this->entityTypeManager->getStorage($this->getEntityType());
|
||||
if ($this->getMachineName()) {
|
||||
$values = $this->getTempstore()->get($this->getMachineName());
|
||||
if (!$values) {
|
||||
@@ -89,24 +91,25 @@ abstract class EntityFormWizardBase extends FormWizardBase implements EntityForm
|
||||
*/
|
||||
public function finish(array &$form, FormStateInterface $form_state) {
|
||||
$cached_values = $form_state->getTemporaryValue('wizard');
|
||||
/** @var $entity \Drupal\Core\Entity\EntityInterface */
|
||||
/** @var \Drupal\Core\Entity\EntityInterface $entity */
|
||||
$entity = $cached_values[$this->getEntityType()];
|
||||
$entity->set('id', $cached_values['id']);
|
||||
$entity->set('label', $cached_values['label']);
|
||||
$status = $entity->save();
|
||||
$definition = $this->entityManager->getDefinition($this->getEntityType());
|
||||
if ($status) {
|
||||
drupal_set_message($this->t('Saved the %label @entity_type.', array(
|
||||
'%label' => $entity->label(),
|
||||
'@entity_type' => $definition->getLabel(),
|
||||
)));
|
||||
|
||||
$arguments = [
|
||||
'@entity-type' => $entity->getEntityType()->getLowercaseLabel(),
|
||||
'%label' => $entity->label(),
|
||||
];
|
||||
if ($status === SAVED_UPDATED) {
|
||||
$this->messenger()->addMessage($this->t('The @entity-type %label has been updated.', $arguments));
|
||||
$this->logger($entity->getEntityType()->getProvider())->notice('Updated @entity-type %label.', $arguments);
|
||||
}
|
||||
else {
|
||||
drupal_set_message($this->t('The %label @entity_type was not saved.', array(
|
||||
'%label' => $entity->label(),
|
||||
'@entity_type' => $definition->getLabel(),
|
||||
)));
|
||||
elseif ($status === SAVED_NEW) {
|
||||
$this->messenger()->addMessage($this->t('The @entity-type %label has been added.', $arguments));
|
||||
$this->logger($entity->getEntityType()->getProvider())->notice('Added @entity-type %label.', $arguments);
|
||||
}
|
||||
|
||||
$form_state->setRedirectUrl($entity->toUrl('collection'));
|
||||
parent::finish($form, $form_state);
|
||||
}
|
||||
@@ -122,7 +125,7 @@ abstract class EntityFormWizardBase extends FormWizardBase implements EntityForm
|
||||
protected function customizeForm(array $form, FormStateInterface $form_state) {
|
||||
$form = parent::customizeForm($form, $form_state);
|
||||
if ($this->machine_name) {
|
||||
$entity = $this->entityManager->getStorage($this->getEntityType())
|
||||
$entity = $this->entityTypeManager->getStorage($this->getEntityType())
|
||||
->load($this->machine_name);
|
||||
}
|
||||
else {
|
||||
@@ -145,7 +148,7 @@ abstract class EntityFormWizardBase extends FormWizardBase implements EntityForm
|
||||
$default_operation = reset($operations);
|
||||
if ($operation['form'] == $default_operation['form']) {
|
||||
// Get the plugin definition of this entity.
|
||||
$definition = $this->entityManager->getDefinition($this->getEntityType());
|
||||
$definition = $this->entityTypeManager->getDefinition($this->getEntityType());
|
||||
// Create id and label form elements.
|
||||
$form['name'] = array(
|
||||
'#type' => 'fieldset',
|
||||
|
||||
@@ -13,7 +13,8 @@ use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\ctools\Ajax\OpenModalWizardCommand;
|
||||
use Drupal\ctools\Event\WizardEvent;
|
||||
use Drupal\user\SharedTempStoreFactory;
|
||||
use Drupal\Core\TempStore\PrivateTempStoreFactory;
|
||||
use Drupal\Core\TempStore\SharedTempStoreFactory;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
/**
|
||||
@@ -24,7 +25,7 @@ abstract class FormWizardBase extends FormBase implements FormWizardInterface {
|
||||
/**
|
||||
* Tempstore Factory for keeping track of values in each step of the wizard.
|
||||
*
|
||||
* @var \Drupal\user\SharedTempStoreFactory
|
||||
* @var \Drupal\Core\TempStore\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
@@ -71,7 +72,7 @@ abstract class FormWizardBase extends FormBase implements FormWizardInterface {
|
||||
protected $step;
|
||||
|
||||
/**
|
||||
* @param \Drupal\user\SharedTempStoreFactory $tempstore
|
||||
* @param \Drupal\Core\TempStore\SharedTempStoreFactory $tempstore
|
||||
* Tempstore Factory for keeping track of values in each step of the
|
||||
* wizard.
|
||||
* @param \Drupal\Core\Form\FormBuilderInterface $builder
|
||||
@@ -103,7 +104,7 @@ abstract class FormWizardBase extends FormBase implements FormWizardInterface {
|
||||
*/
|
||||
public static function getParameters() {
|
||||
return [
|
||||
'tempstore' => \Drupal::service('user.shared_tempstore'),
|
||||
'tempstore' => \Drupal::service('tempstore.shared'),
|
||||
'builder' => \Drupal::service('form_builder'),
|
||||
'class_resolver' => \Drupal::service('class_resolver'),
|
||||
'event_dispatcher' => \Drupal::service('event_dispatcher'),
|
||||
@@ -131,7 +132,8 @@ abstract class FormWizardBase extends FormBase implements FormWizardInterface {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTempstore() {
|
||||
return $this->tempstore->get($this->getTempstoreId());
|
||||
$tempstore = $this->tempstore->get($this->getTempstoreId());
|
||||
return $tempstore;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -393,7 +395,7 @@ abstract class FormWizardBase extends FormBase implements FormWizardInterface {
|
||||
$actions['submit']['#ajax'] = [
|
||||
'callback' => '::ajaxSubmit',
|
||||
'url' => Url::fromRoute($this->getRouteName(), $parameters),
|
||||
'options' => ['query' => \Drupal::request()->query->all() + [FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]],
|
||||
'options' => ['query' => $this->getRequest()->query->all() + [FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -419,7 +421,7 @@ abstract class FormWizardBase extends FormBase implements FormWizardInterface {
|
||||
$actions['previous']['#ajax'] = [
|
||||
'callback' => '::ajaxPrevious',
|
||||
'url' => Url::fromRoute($this->getRouteName(), $parameters),
|
||||
'options' => ['query' => \Drupal::request()->query->all() + [FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]],
|
||||
'options' => ['query' => $this->getRequest()->query->all() + [FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ interface FormWizardInterface extends FormInterface {
|
||||
/**
|
||||
* The active SharedTempStore for this wizard.
|
||||
*
|
||||
* @return \Drupal\user\SharedTempStore
|
||||
* @return \Drupal\Core\TempStore\SharedTempStore
|
||||
*/
|
||||
public function getTempstore();
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Drupal\ctools\Wizard;
|
||||
use Drupal\Core\Form\FormBuilderInterface;
|
||||
use Drupal\Core\Form\FormState;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Drupal\Core\Render\Renderer;
|
||||
|
||||
class WizardFactory implements WizardFactoryInterface {
|
||||
|
||||
@@ -23,14 +24,26 @@ class WizardFactory implements WizardFactoryInterface {
|
||||
protected $dispatcher;
|
||||
|
||||
/**
|
||||
* The object renderer.
|
||||
*
|
||||
* @var \Drupal\Core\Render\Renderer
|
||||
*/
|
||||
protected $renderer;
|
||||
|
||||
/**
|
||||
* The construct method.
|
||||
*
|
||||
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
|
||||
* The form builder.
|
||||
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
|
||||
* The event dispatcher.
|
||||
* @param \Drupal\Core\Render\Renderer $renderer
|
||||
* The object renderer.
|
||||
*/
|
||||
public function __construct(FormBuilderInterface $form_builder, EventDispatcherInterface $event_dispatcher) {
|
||||
public function __construct(FormBuilderInterface $form_builder, EventDispatcherInterface $event_dispatcher, Renderer $renderer) {
|
||||
$this->builder = $form_builder;
|
||||
$this->dispatcher = $event_dispatcher;
|
||||
$this->renderer = $renderer;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,9 +55,8 @@ class WizardFactory implements WizardFactoryInterface {
|
||||
|
||||
if ($ajax) {
|
||||
$form['#attached']['library'][] = 'core/drupal.dialog.ajax';
|
||||
$status_messages = array('#type' => 'status_messages');
|
||||
// @todo properly inject the renderer. Core should really be doing this work.
|
||||
if ($messages = \Drupal::service('renderer')->renderRoot($status_messages)) {
|
||||
$status_messages = ['#type' => 'status_messages'];
|
||||
if ($messages = $this->renderer->renderRoot($status_messages)) {
|
||||
if (!empty($form['#prefix'])) {
|
||||
// Form prefix is expected to be a string. Prepend the messages to
|
||||
// that string.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\ctools\Wizard;
|
||||
|
||||
interface WizardFactoryInterface {
|
||||
|
||||
Reference in New Issue
Block a user