diff --git a/src/Controller/PageManagerController.php b/src/Controller/PageManagerController.php index 48acec8..91642b9 100644 --- a/src/Controller/PageManagerController.php +++ b/src/Controller/PageManagerController.php @@ -100,8 +100,8 @@ public function editPageTitle(PageInterface $page) { /** * Route title callback. * - * @param \Drupal\page_manager\PageVariantEntityInterface $page - * The page entity. + * @param \Drupal\page_manager\PageVariantEntityInterface $page_variant + * The page variant entity. * * @return string * The title for the page variant edit form. @@ -129,8 +129,8 @@ public function editAccessConditionTitle(PageInterface $page, $condition_id) { /** * Route title callback. * - * @param \Drupal\page_manager\PageVariantEntityInterface $page - * The page entity. + * @param \Drupal\page_manager\PageVariantEntityInterface $page_variant + * The page variant entity. * @param string $condition_id * The selection condition ID. * diff --git a/src/Entity/Page.php b/src/Entity/Page.php index 8423c1d..96872be 100644 --- a/src/Entity/Page.php +++ b/src/Entity/Page.php @@ -79,7 +79,7 @@ class Page extends ConfigEntityBase implements PageInterface { /** * The page variant entities. * - * @var \Drupal\page_manager\Entity\PageVariantEntity[]. + * @var \Drupal\page_manager\PageVariantEntityInterface[]. */ protected $displayVariants; @@ -350,11 +350,14 @@ public function addVariant(array $configuration) { $configuration['id'] = $this->id() . '.' . $configuration['id']; } $configuration['page'] = $this->id(); - /** @var $variant \Drupal\page_manager\PageVariantEntityInterface */ + /** @var \Drupal\page_manager\PageVariantEntityInterface $variant */ $variant = $this->entityStorage()->create($configuration); return $this->addVariantEntity($variant); } + /** + * {@inheritdoc} + */ public function addVariantEntity(PageVariantEntityInterface $variant) { $this->displayVariants[$variant->id()] = $variant; return $variant->id(); @@ -385,7 +388,7 @@ public function removeVariant($variant_id) { public function getVariants() { if (!isset($this->displayVariants)) { $this->displayVariants = []; - /** @var $variant \Drupal\page_manager\PageVariantEntityInterface */ + /** @var \Drupal\page_manager\PageVariantEntityInterface $variant */ foreach ($this->entityStorage()->loadByProperties(['page' => $this->id()]) as $variant) { $this->displayVariants[$variant->uuid()] = $variant; } diff --git a/src/Entity/PageVariantEntity.php b/src/Entity/PageVariantEntity.php index f4079d8..15e5052 100644 --- a/src/Entity/PageVariantEntity.php +++ b/src/Entity/PageVariantEntity.php @@ -10,10 +10,7 @@ use Drupal\Core\Condition\ConditionPluginCollection; use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Entity\EntityStorageInterface; -use Drupal\Core\Plugin\ContextAwarePluginInterface; -use Drupal\Core\Session\AccountInterface; use Drupal\page_manager\PageVariantEntityInterface; -use Drupal\page_manager\Plugin\ContextAwareVariantInterface; /** * Defines the page variant entity. diff --git a/src/Form/DisplayVariantAddBlockForm.php b/src/Form/DisplayVariantAddBlockForm.php index 175b274..d76da93 100644 --- a/src/Form/DisplayVariantAddBlockForm.php +++ b/src/Form/DisplayVariantAddBlockForm.php @@ -56,8 +56,8 @@ public function getFormId() { */ protected function prepareBlock($plugin_id) { $block = $this->blockManager->createInstance($plugin_id); - $block_id = $this->pageVariant->getVariantPlugin()->addBlock($block->getConfiguration()); - return $this->pageVariant->getVariantPlugin()->getBlock($block_id); + $block_id = $this->getVariantPlugin()->addBlock($block->getConfiguration()); + return $this->getVariantPlugin()->getBlock($block_id); } /** diff --git a/src/Form/DisplayVariantConfigureBlockFormBase.php b/src/Form/DisplayVariantConfigureBlockFormBase.php index b8eac83..3bf3500 100644 --- a/src/Form/DisplayVariantConfigureBlockFormBase.php +++ b/src/Form/DisplayVariantConfigureBlockFormBase.php @@ -72,8 +72,8 @@ public function buildForm(array $form, FormStateInterface $form_state, PageVaria $form['region'] = [ '#title' => $this->t('Region'), '#type' => 'select', - '#options' => $this->pageVariant->getVariantPlugin()->getRegionNames(), - '#default_value' => $this->pageVariant->getVariantPlugin()->getRegionAssignment($this->block->getConfiguration()['uuid']), + '#options' => $this->getVariantPlugin()->getRegionNames(), + '#default_value' => $this->getVariantPlugin()->getRegionAssignment($this->block->getConfiguration()['uuid']), '#required' => TRUE, ]; @@ -95,7 +95,7 @@ public function buildForm(array $form, FormStateInterface $form_state, PageVaria public function validateForm(array &$form, FormStateInterface $form_state) { // The page might have been serialized, resulting in a new display variant // collection. Refresh the block object. - $this->block = $this->pageVariant->getVariantPlugin()->getBlock($form_state->get('block_id')); + $this->block = $this->getVariantPlugin()->getBlock($form_state->get('block_id')); $settings = (new FormState())->setValues($form_state->getValue('settings')); // Call the plugin validate handler. @@ -119,7 +119,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $this->block->setContextMapping($form_state->getValue('context_mapping', [])); } - $this->pageVariant->getVariantPlugin()->updateBlock($this->block->getConfiguration()['uuid'], ['region' => $form_state->getValue('region')]); + $this->getVariantPlugin()->updateBlock($this->block->getConfiguration()['uuid'], ['region' => $form_state->getValue('region')]); $this->pageVariant->save(); $form_state->setRedirect('entity.page_variant.edit_form', [ @@ -127,4 +127,13 @@ public function submitForm(array &$form, FormStateInterface $form_state) { ]); } + /** + * @todo. + * + * @return \Drupal\ctools\Plugin\BlockVariantInterface + */ + protected function getVariantPlugin() { + return $this->pageVariant->getVariantPlugin(); + } + } diff --git a/src/Form/DisplayVariantDeleteBlockForm.php b/src/Form/DisplayVariantDeleteBlockForm.php index 5ff51b1..237ed7a 100644 --- a/src/Form/DisplayVariantDeleteBlockForm.php +++ b/src/Form/DisplayVariantDeleteBlockForm.php @@ -66,7 +66,7 @@ public function getConfirmText() { */ public function buildForm(array $form, FormStateInterface $form_state, PageVariantEntityInterface $page_variant = NULL, $block_id = NULL) { $this->pageVariant = $page_variant; - $this->block = $this->pageVariant->getVariantPlugin()->getBlock($block_id); + $this->block = $this->getVariantPlugin()->getBlock($block_id); return parent::buildForm($form, $form_state); } @@ -74,11 +74,20 @@ public function buildForm(array $form, FormStateInterface $form_state, PageVaria * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $this->pageVariant->getVariantPlugin()->removeBlock($this->block->getConfiguration()['uuid']); + $this->getVariantPlugin()->removeBlock($this->block->getConfiguration()['uuid']); $this->pageVariant->save(); drupal_set_message($this->t('The block %label has been removed.', ['%label' => $this->block->label()])); $form_state->setRedirectUrl($this->getCancelUrl()); } + /** + * @todo. + * + * @return \Drupal\ctools\Plugin\BlockVariantInterface + */ + protected function getVariantPlugin() { + return $this->pageVariant->getVariantPlugin(); + } + } diff --git a/src/Form/DisplayVariantEditBlockForm.php b/src/Form/DisplayVariantEditBlockForm.php index ba101e4..28870ad 100644 --- a/src/Form/DisplayVariantEditBlockForm.php +++ b/src/Form/DisplayVariantEditBlockForm.php @@ -23,7 +23,7 @@ public function getFormId() { * {@inheritdoc} */ protected function prepareBlock($block_id) { - return $this->pageVariant->getVariantPlugin()->getBlock($block_id); + return $this->getVariantPlugin()->getBlock($block_id); } /** diff --git a/src/Form/PageVariantAddForm.php b/src/Form/PageVariantAddForm.php index 48b142a..4fd63fb 100644 --- a/src/Form/PageVariantAddForm.php +++ b/src/Form/PageVariantAddForm.php @@ -7,9 +7,7 @@ namespace Drupal\page_manager\Form; -use Drupal\Core\Entity\EntityForm; use Drupal\Core\Form\FormStateInterface; -use Drupal\page_manager\Entity\Page; use Drupal\page_manager\PageVariantEntityInterface; /** @@ -18,6 +16,7 @@ * @package Drupal\page_manager\Form */ class PageVariantAddForm extends PageVariantFormBase { + /** * {@inheritdoc} */ diff --git a/src/Form/PageVariantConfigureForm.php b/src/Form/PageVariantConfigureForm.php index fe3c543..ebb15a7 100644 --- a/src/Form/PageVariantConfigureForm.php +++ b/src/Form/PageVariantConfigureForm.php @@ -1,16 +1,17 @@ getTemporaryValue('wizard'); - /** @var $page_variant \Drupal\page_manager\Entity\PageVariantEntity */ + /** @var \Drupal\page_manager\PageVariantEntityInterface $page_variant */ $page_variant = $cached_values['variant']; $variant = $page_variant->getVariantPlugin(); return $variant->buildConfigurationForm($form, $form_state); @@ -51,9 +52,9 @@ public function buildForm(array $form, FormStateInterface $form_state) { */ public function submitForm(array &$form, FormStateInterface $form_state) { $cached_values = $form_state->getTemporaryValue('wizard'); - /** @var $page \Drupal\page_manager\Entity\Page */ + /** @var \Drupal\page_manager\PageInterface $page */ $page = $cached_values['page']; - /** @var $page_variant \Drupal\page_manager\Entity\PageVariantEntity */ + /** @var \Drupal\page_manager\PageVariantEntityInterface $page_variant */ $page_variant = $cached_values['variant']; $variant = $page_variant->getVariantPlugin(); $variant->submitConfigurationForm($form, $form_state); diff --git a/src/Form/PageVariantDeleteForm.php b/src/Form/PageVariantDeleteForm.php index dfc9781..886e310 100644 --- a/src/Form/PageVariantDeleteForm.php +++ b/src/Form/PageVariantDeleteForm.php @@ -15,6 +15,14 @@ * Builds the form to delete a PageVariant. */ class PageVariantDeleteForm extends EntityConfirmFormBase { + + /** + * The entity being used by this form. + * + * @var \Drupal\page_manager\PageVariantEntityInterface + */ + protected $entity; + /** * {@inheritdoc} */ diff --git a/src/Form/PageVariantEditForm.php b/src/Form/PageVariantEditForm.php index 2e50c5a..129f7f6 100644 --- a/src/Form/PageVariantEditForm.php +++ b/src/Form/PageVariantEditForm.php @@ -7,15 +7,10 @@ namespace Drupal\page_manager\Form; -use Drupal\Core\Entity\EntityForm; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; -use Drupal\page_manager\Entity\Page; -use Drupal\page_manager\PageVariantEntityInterface; use Drupal\ctools\Form\AjaxFormTrait; use Drupal\ctools\Plugin\BlockVariantInterface; -use Drupal\ctools\Plugin\ConditionVariantInterface; -use Drupal\page_manager\PageInterface; /** * Provides a form for editing a display variant. @@ -32,7 +27,7 @@ protected function submitText() { } /** - * @{inheritdoc} + * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); @@ -52,11 +47,12 @@ public function form(array $form, FormStateInterface $form_state) { * @return array */ protected function buildBlockForm() { - if (!$this->getVariantPlugin() instanceof BlockVariantInterface) { + $variant_plugin = $this->getVariantPlugin(); + if (!$variant_plugin instanceof BlockVariantInterface) { return []; } - /** @var \Drupal\page_manager\PageVariantInterface $page_variant */ + /** @var \Drupal\page_manager\PageVariantEntityInterface $page_variant */ $page_variant = $this->getEntity(); // Set up the attributes used by a modal to prevent duplication later. @@ -64,7 +60,7 @@ protected function buildBlockForm() { $add_button_attributes = $this->getAjaxButtonAttributes(); $form = []; - if ($block_assignments = $this->getVariantPlugin()->getRegionAssignments()) { + if ($block_assignments = $variant_plugin->getRegionAssignments()) { // Build a table of all blocks used by this display variant. $form = [ '#type' => 'details', @@ -121,7 +117,7 @@ protected function buildBlockForm() { ], ]; $form['blocks'][$region]['title'] = [ - '#markup' => $this->getVariantPlugin()->getRegionName($region), + '#markup' => $variant_plugin->getRegionName($region), '#wrapper_attributes' => [ 'colspan' => 5, ], @@ -156,8 +152,8 @@ protected function buildBlockForm() { '#title' => $this->t('Region'), '#title_display' => 'invisible', '#type' => 'select', - '#options' => $this->getVariantPlugin()->getRegionNames(), - '#default_value' => $this->getVariantPlugin()->getRegionAssignment($block_id), + '#options' => $variant_plugin->getRegionNames(), + '#default_value' => $variant_plugin->getRegionAssignment($block_id), '#attributes' => [ 'class' => ['block-region-select', 'block-region-' . $region], ], @@ -290,11 +286,12 @@ protected function buildSelectionForm() { public function save(array $form, FormStateInterface $form_state) { // @todo This feels very wrong. - if ($this->getVariantPlugin() instanceof BlockVariantInterface) { + $variant_plugin = $this->getVariantPlugin(); + if ($variant_plugin instanceof BlockVariantInterface) { // If the blocks were rearranged, update their values. if (!$form_state->isValueEmpty(['display_variant', 'blocks'])) { foreach ($form_state->getValue(['display_variant', 'blocks']) as $block_id => $block_values) { - $this->getVariantPlugin()->updateBlock($block_id, $block_values); + $variant_plugin->updateBlock($block_id, $block_values); } } } diff --git a/src/Form/PageVariantFormBase.php b/src/Form/PageVariantFormBase.php index 5913f1e..2c09a0e 100644 --- a/src/Form/PageVariantFormBase.php +++ b/src/Form/PageVariantFormBase.php @@ -11,7 +11,6 @@ use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\Form\FormState; use Drupal\Core\Form\FormStateInterface; -use Drupal\page_manager\Entity\Page; use Drupal\page_manager\PageVariantEntityInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -21,6 +20,7 @@ * @package Drupal\page_manager\Form */ abstract class PageVariantFormBase extends EntityForm { + /** * The display variant plugin for this page variant entity. * diff --git a/src/PageInterface.php b/src/PageInterface.php index fadec22..6ff6bb5 100644 --- a/src/PageInterface.php +++ b/src/PageInterface.php @@ -9,7 +9,6 @@ use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Entity\EntityWithPluginCollectionInterface; -use Drupal\page_manager\Plugin\VariantAwareInterface; /** * Provides an interface for page entities. @@ -59,6 +58,15 @@ public function usesAdminTheme(); public function addVariant(array $configuration); /** + * @todo. + * + * @param \Drupal\page_manager\PageVariantEntityInterface $variant + * + * @return string + */ + public function addVariantEntity(PageVariantEntityInterface $variant); + + /** * Retrieves a specific variant. * * @param string $variant_id