Commit cacdeb61 authored by paulocs's avatar paulocs Committed by paulocs

Issue #3161742 by paulocs: Fix Drupal Code Standards using phpcbf

parent 583073cf
......@@ -34,7 +34,7 @@ function context_update_8002() {
$context_manager = \Drupal::service('context.manager');
foreach ($context_manager->getContexts() as $context) {
foreach ($context->getReactions() as $reaction) {
if ($reaction instanceof \Drupal\context\Plugin\ContextReaction\Blocks) {
if ($reaction instanceof Blocks) {
foreach ($reaction->getBlocks() as $block) {
$configuration = $block->getConfiguration();
if (!isset($configuration['css_class'])) {
......
<?php
/**
* @file
*/
use Drupal\Core\Render\Markup;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Component\Utility\NestedArray;
......@@ -12,14 +16,14 @@ function context_help($route_name, RouteMatchInterface $route_match) {
case 'help.page.context':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>'.t('The Context module lets users define conditions for when certain reactions should take place.').'</p>';
$output .= '<p>'.t('An example of a condition could be when viewing a certain node type and blocks should be placed as a reaction when viewing a page with this node type.').'</p>';
$output .= '<p>' . t('The Context module lets users define conditions for when certain reactions should take place.') . '</p>';
$output .= '<p>' . t('An example of a condition could be when viewing a certain node type and blocks should be placed as a reaction when viewing a page with this node type.') . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Managing context') . '</dt>';
$output .= '<dd>' . t('Users with <em>Administer contexts</em> permission can add contextual conditions and reactions for different portions of their site. For each context, they can choose the conditions that trigger this context to be active and choose different aspects of their site that should react to this active context.') . '</dd>';
$output .= '<dt>' . t('Adding new custom reactions') . '</dt>';
$output .= '<dd>' . t('Reactions for the context module are defined trough the new <a href=":link">Drupal 8 Plugin API</a>.', [':link' =>'https://www.drupal.org/developing/api/8/plugins']) . '</dd>';
$output .= '<dd>' . t('Reactions for the context module are defined trough the new <a href=":link">Drupal 8 Plugin API</a>.', [':link' => 'https://www.drupal.org/developing/api/8/plugins']) . '</dd>';
$output .= '<dd>' . t('The Context module defines a plugin type named ContextReaction that users can extend when creating their own plugins.') . '</dd>';
$output .= '<dd>' . t('A context reaction requires a configuration form and execute method. The execution of the plugin is also something that will have to be handled by the author of the reaction.') . '</dd>';
$output .= '</dl>';
......
<?php
/**
* @file
*/
/**
*
*/
function context_ui_context_insert($entity) {
Drupal::service('context_ui.menu_builder')->addSubMenuItem($entity);
}
/**
*
*/
function context_ui_context_update($entity) {
Drupal::service('context_ui.menu_builder')->updateSubMenuItem($entity);
}
/**
*
*/
function context_ui_context_delete($entity) {
Drupal::service('context_ui.menu_builder')->deleteSubMenuItem($entity);
}
\ No newline at end of file
}
services:
context_ui.menu_builder:
class: Drupal\context_ui\MenuBuilder
arguments: ['@plugin.manager.menu.link']
\ No newline at end of file
arguments: ['@plugin.manager.menu.link']
......@@ -2,7 +2,6 @@
namespace Drupal\context_ui;
use Drupal\context\ContextInterface;
use Drupal\context\ContextManager;
use Drupal\context\Entity\Context;
use Drupal\Component\Utility\Html;
......@@ -16,6 +15,9 @@ use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Messenger\MessengerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
*
*/
class ContextListBuilder extends ConfigEntityListBuilder implements FormInterface {
use AjaxFormTrait;
......@@ -23,12 +25,12 @@ class ContextListBuilder extends ConfigEntityListBuilder implements FormInterfac
/**
* The Context modules context manager.
*
* @var ContextManager
* @var \Drupal\context\ContextManager
*/
protected $contextManager;
/**
* @var FormBuilderInterface
* @var \Drupal\Core\Form\FormBuilderInterface
*/
protected $formBuilder;
......@@ -168,7 +170,7 @@ class ContextListBuilder extends ConfigEntityListBuilder implements FormInterfac
],
];
/** @var ContextInterface $context */
/** @var \Drupal\context\ContextInterface $context */
foreach ($contexts as $context_id => $context) {
$operations = [
'edit' => [
......@@ -184,7 +186,7 @@ class ContextListBuilder extends ConfigEntityListBuilder implements FormInterfac
'title' => $context->disabled() ? $this->t('Enable') : $this->t('Disable'),
'url' => $context->toUrl('disable-form'),
'attributes' => $this->getAjaxAttributes(),
]
],
];
$form['contexts'][$context_id] = [
......@@ -254,7 +256,7 @@ class ContextListBuilder extends ConfigEntityListBuilder implements FormInterfac
public function submitForm(array &$form, FormStateInterface $form_state) {
$contexts = $this->storage->loadMultiple(array_keys($form_state->getValue('contexts')));
/*** @var ContextInterface $context */
/*** @var \Drupal\context\ContextInterface $context */
foreach ($contexts as $context_id => $context) {
$context_values = $form_state->getValue(['contexts', $context_id]);
......
......@@ -16,46 +16,48 @@ use Drupal\Core\Ajax\CloseModalDialogCommand;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\Component\Plugin\Exception\PluginException;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
*
*/
class ContextUIController extends ControllerBase {
/**
* The context reaction manager.
*
* @var ContextReactionManager
* @var \Drupal\context\ContextReactionManager
*/
protected $contextReactionManager;
/**
* The Context module context manager.
*
* @var ContextManager
* @var \Drupal\context\ContextManager
*/
protected $contextManager;
/**
* The Drupal core condition manager.
*
* @var ConditionManager
* @var \Drupal\Core\Condition\ConditionManager
*/
protected $conditionManager;
/**
* Construct a new context controller.
*
* @param ContextManager $contextManager
* @param \Drupal\context\ContextManager $contextManager
* The Context module context manager.
*
* @param ContextReactionManager $contextReactionManager
* @param \Drupal\context\ContextReactionManager $contextReactionManager
* The Context module context reaction plugin manager.
*
* @param ConditionManager $conditionManager
* @param \Drupal\Core\Condition\ConditionManager $conditionManager
* The Drupal core condition manager.
*/
function __construct(
public function __construct(
ContextManager $contextManager,
ContextReactionManager $contextReactionManager,
ConditionManager $conditionManager
......@@ -79,10 +81,10 @@ class ContextUIController extends ControllerBase {
/**
* Retrieves group suggestions for a context.
*
* @param Request $request
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request.
*
* @return JsonResponse
* @return \Symfony\Component\HttpFoundation\JsonResponse
* A JSON response with groups matching the query.
*/
public function groupsAutocomplete(Request $request) {
......@@ -112,7 +114,7 @@ class ContextUIController extends ControllerBase {
/**
* Displays a list of conditions that can be added to the context.
*
* @param ContextInterface $context
* @param \Drupal\context\ContextInterface $context
* The context to display available conditions for.
*
* @return array
......@@ -123,7 +125,7 @@ class ContextUIController extends ControllerBase {
$conditions = $this->conditionManager->getDefinitions();
$header = [
$this->t('Condition')
$this->t('Condition'),
];
$build['filter'] = [
......@@ -163,7 +165,7 @@ class ContextUIController extends ControllerBase {
],
'#options' => [
'html' => TRUE,
]
],
],
],
];
......@@ -187,8 +189,8 @@ class ContextUIController extends ControllerBase {
/**
* Displays a list of reactions that can be added to the context.
*
* @param ContextInterface $context
* The context to display available
* @param \Drupal\context\ContextInterface $context
* The context to display available.
*
* @return array
*/
......@@ -198,7 +200,7 @@ class ContextUIController extends ControllerBase {
$reactions = $this->contextReactionManager->getDefinitions();
$header = [
$this->t('Reactions')
$this->t('Reactions'),
];
$build['filter'] = [
......@@ -262,16 +264,16 @@ class ContextUIController extends ControllerBase {
/**
* Add the specified reaction to the context.
*
* @param Request $request
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request.
*
* @param ContextInterface $context
* @param \Drupal\context\ContextInterface $context
* The context to add the reaction to.
*
* @param $reaction_id
* The ID of the reaction to add.
*
* @return AjaxResponse|RedirectResponse
* @return \Drupal\Core\Ajax\AjaxResponse|RedirectResponse
*/
public function addReaction(Request $request, ContextInterface $context, $reaction_id) {
......@@ -328,16 +330,16 @@ class ContextUIController extends ControllerBase {
/**
* Add the specified condition to the context.
*
* @param Request $request
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request.
*
* @param ContextInterface $context
* @param \Drupal\context\ContextInterface $context
* The context to add the condition to.
*
* @param $condition_id
* The ID of the condition to add.
*
* @return AjaxResponse|RedirectResponse
* @return \Drupal\Core\Ajax\AjaxResponse|RedirectResponse
*/
public function addCondition(Request $request, ContextInterface $context, $condition_id) {
......@@ -361,7 +363,7 @@ class ContextUIController extends ControllerBase {
if ($reaction->getPluginId() == 'theme') {
if ($request->isXmlHttpRequest()) {
$response = new AjaxResponse();
$response->addCommand(new CloseModalDialogCommand());
$response->addCommand(new OpenModalDialogCommand($this->t("Current theme condition"), $this->t("You can not set Current theme condition if Theme reaction is set."), ['width' => '700']));
return $response;
......
......@@ -11,6 +11,9 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Ajax\CloseModalDialogCommand;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
*
*/
class ConditionDeleteForm extends ConfirmFormBase {
/**
......@@ -37,7 +40,7 @@ class ConditionDeleteForm extends ConfirmFormBase {
/**
* Construct a condition delete form.
*
* @param ContextManager $contextManager
* @param \Drupal\context\ContextManager $contextManager
*/
public function __construct(ContextManager $contextManager) {
$this->contextManager = $contextManager;
......@@ -47,7 +50,7 @@ class ConditionDeleteForm extends ConfirmFormBase {
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static (
return new static(
$container->get('context.manager')
);
}
......@@ -100,7 +103,7 @@ class ConditionDeleteForm extends ConfirmFormBase {
// Submit the form with AJAX if possible.
$form['actions']['submit']['#ajax'] = [
'callback' => '::submitFormAjax'
'callback' => '::submitFormAjax',
];
return $form;
......@@ -116,7 +119,8 @@ class ConditionDeleteForm extends ConfirmFormBase {
// If this is not an AJAX request then redirect and show a message.
if (!$this->getRequest()->isXmlHttpRequest()) {
$this->messenger()->addMessage($this->t('The condition %name has been removed.', [
'%name' => $this->condition->getPluginDefinition()['label']]
'%name' => $this->condition->getPluginDefinition()['label'],
]
));
$form_state->setRedirectUrl($this->getCancelUrl());
......@@ -126,7 +130,7 @@ class ConditionDeleteForm extends ConfirmFormBase {
/**
* Handle when the form is submitted trough AJAX.
*
* @return AjaxResponse
* @return \Drupal\Core\Ajax\AjaxResponse
*/
public function submitFormAjax() {
$contextForm = $this->contextManager->getForm($this->context, 'edit');
......
......@@ -4,6 +4,9 @@ namespace Drupal\context_ui\Form;
use Drupal\Core\Form\FormStateInterface;
/**
*
*/
class ContextAddForm extends ContextFormBase {
/**
......@@ -27,4 +30,3 @@ class ContextAddForm extends ContextFormBase {
}
}
......@@ -8,17 +8,20 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
*
*/
class ContextDeleteForm extends EntityConfirmFormBase {
/**
* @var ContextManager
* @var \Drupal\context\ContextManager
*/
protected $contextManager;
/**
* @param ContextManager $contextManager
* @param \Drupal\context\ContextManager $contextManager
*/
function __construct(ContextManager $contextManager) {
public function __construct(ContextManager $contextManager) {
$this->contextManager = $contextManager;
}
......@@ -63,7 +66,6 @@ class ContextDeleteForm extends EntityConfirmFormBase {
return $form;
}
/**
* {@inheritdoc}
*/
......@@ -76,4 +78,5 @@ class ContextDeleteForm extends EntityConfirmFormBase {
$formState->setRedirectUrl($this->getCancelUrl());
}
}
......@@ -8,6 +8,9 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
*
*/
class ContextDisableForm extends EntityConfirmFormBase {
/**
......
......@@ -8,6 +8,9 @@ use Drupal\context\Form\AjaxFormTrait;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Form\FormStateInterface;
/**
*
*/
class ContextEditForm extends ContextFormBase {
use AjaxFormTrait;
......@@ -75,7 +78,7 @@ class ContextEditForm extends ContextFormBase {
* @param $element
* The element to process.
*
* @param FormStateInterface $form_state
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current form state.
*
* @return array
......@@ -91,7 +94,7 @@ class ContextEditForm extends ContextFormBase {
]),
'#attributes' => [
'class' => [
'use-ajax', 'button', 'button--small'
'use-ajax', 'button', 'button--small',
],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
......@@ -131,7 +134,7 @@ class ContextEditForm extends ContextFormBase {
]),
'#attributes' => [
'class' => [
'use-ajax', 'button', 'button--small'
'use-ajax', 'button', 'button--small',
],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
......@@ -150,7 +153,7 @@ class ContextEditForm extends ContextFormBase {
* @param $element
* The element to process.
*
* @param FormStateInterface $form_state
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current form state.
*
* @return array
......@@ -166,7 +169,7 @@ class ContextEditForm extends ContextFormBase {
]),
'#attributes' => [
'class' => [
'use-ajax', 'button', 'button--small'
'use-ajax', 'button', 'button--small',
],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
......@@ -209,7 +212,7 @@ class ContextEditForm extends ContextFormBase {
]),
'#attributes' => [
'class' => [
'use-ajax', 'button', 'button--small'
'use-ajax', 'button', 'button--small',
],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
......
......@@ -11,6 +11,9 @@ use Drupal\Core\Plugin\ContextAwarePluginInterface;
use Drupal\Core\Plugin\Context\ContextRepositoryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
*
*/
abstract class ContextFormBase extends EntityForm {
/**
......@@ -23,24 +26,24 @@ abstract class ContextFormBase extends EntityForm {
/**
* The Context module context manager.
*
* @var ContextManager
* @var \Drupal\context\ContextManager
*/
protected $contextManager;
/**
* The Drupal context repository.
*
* @var ContextRepositoryInterface
* @var \Drupal\context\Entity\ContextRepositoryInterface
*/
protected $contextRepository;
/**
* Construct a new context form.
*
* @param ContextManager $contextManager
* @param ContextRepositoryInterface $contextRepository
* @param \Drupal\context\ContextManager $contextManager
* @param \Drupal\context\Entity\ContextRepositoryInterface $contextRepository
*/
function __construct(ContextManager $contextManager, ContextRepositoryInterface $contextRepository) {
public function __construct(ContextManager $contextManager, ContextRepositoryInterface $contextRepository) {
$this->contextManager = $contextManager;
$this->contextRepository = $contextRepository;
}
......@@ -143,7 +146,7 @@ abstract class ContextFormBase extends EntityForm {
* @param array $form
* The rendered form.
*
* @param FormStateInterface $form_state
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current form state.
*/
private function handleConditions(array &$form, FormStateInterface $form_state) {
......@@ -171,7 +174,7 @@ abstract class ContextFormBase extends EntityForm {
* @param array $form
* The rendered form.
*
* @param FormStateInterface $form_state
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current form state.
*/
private function handleReactions(array &$form, FormStateInterface $form_state) {
......@@ -193,7 +196,7 @@ abstract class ContextFormBase extends EntityForm {
* @param array $form
* The rendered form.
*
* @param FormStateInterface $form_state
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current form state.
*/
private function validateReactions(array &$form, FormStateInterface $form_state) {
......@@ -243,4 +246,5 @@ abstract class ContextFormBase extends EntityForm {
public function contextExists($name) {
return $this->contextManager->contextExists($name);
}
}
......@@ -8,36 +8,38 @@ use Drupal\context\ContextInterface;
use Drupal\Core\Ajax\ReplaceCommand;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\context\ContextReactionInterface;
use Drupal\Core\Ajax\CloseModalDialogCommand;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
/**
*
*/
class ReactionDeleteForm extends ConfirmFormBase implements ContainerInjectionInterface {
/**
* @var ContextInterface
* @var \Drupal\context\ContextInterface
*/
protected $context;
/**
* @var ContextReactionInterface
* @var \Drupal\context\ContextReactionInterface
*/
protected $reaction;
/**
* The Context module context manager.
*
* @var ContextManager
* @var \Drupal\context\ContextManager
*/
protected $contextManager;
/**
* Construct.
*
* @param ContextManager $contextManager
* @param \Drupal\context\ContextManager $contextManager
*/
function __construct(ContextManager $contextManager) {
public function __construct(ContextManager $contextManager) {
$this->contextManager = $contextManager;
}
......@@ -118,7 +120,8 @@ class ReactionDeleteForm extends ConfirmFormBase implements ContainerInjectionIn
// If this is not an AJAX request then redirect and show a message.
if (!$this->getRequest()->isXmlHttpRequest()) {
$this->messenger()->addMessage($this->t('The %label context reaction has been removed.', [
'%label' => $definition['label']]
'%label' => $definition['label'],
]
));
$form_state->setRedirectUrl($this->getCancelUrl());
......@@ -128,7 +131,7 @@ class ReactionDeleteForm extends ConfirmFormBase implements ContainerInjectionIn
/**
* Handle when the form is submitted through AJAX.
*
* @return AjaxResponse
* @return \Drupal\Core\Ajax\AjaxResponse
*/
public function submitFormAjax() {
$response = new AjaxResponse();
......@@ -140,4 +143,5 @@ class ReactionDeleteForm extends ConfirmFormBase implements ContainerInjectionIn
return $response;
}
}
......@@ -9,14 +9,14 @@ use Drupal\menu_link_content\Entity\MenuLinkContent;
/**
* Implements the MenuBuilder class, which configures and updates the submenu
* context items
* context items.
*
* @package Drupal\context_ui
*/
class MenuBuilder {
/**
* @var \Drupal\Core\Menu\MenuLinkManagerInterface Stores the menuLinkManager interface.
* @var \Drupal\Core\Menu\MenuLinkManagerInterfaceStoresthemenuLinkManagerinterface
*/
protected $menuLinkManager;
......@@ -30,8 +30,8 @@ class MenuBuilder {
}
/**
*
* Create function.
*
* @param \Drupal\context_ui\ContainerInterface $container
*
* @return static
......@@ -43,10 +43,10 @@ class MenuBuilder {
}
/**