diff --git a/contextual_links_example/contextual_links_example.module b/contextual_links_example/contextual_links_example.module index b063edb..c02cea8 100644 --- a/contextual_links_example/contextual_links_example.module +++ b/contextual_links_example/contextual_links_example.module @@ -1,6 +1,13 @@ [ 'template' => 'contextual-links-example-entity', 'render element' => 'element', - ] + ], ]; } @@ -20,4 +27,4 @@ function template_preprocess_contextual_links_example_entity(&$variables) { // variables that we will print in the template file. $variables['title'] = $variables['element']['#object']->titleContent(); $variables['content'] = $variables['element']['#object']->bodyContent(); -} \ No newline at end of file +} diff --git a/contextual_links_example/contextual_links_example.routing.yml b/contextual_links_example/contextual_links_example.routing.yml index eee3d38..c2febee 100644 --- a/contextual_links_example/contextual_links_example.routing.yml +++ b/contextual_links_example/contextual_links_example.routing.yml @@ -12,7 +12,7 @@ contextual_links_example.contextual_links_object_list: path: 'examples/contextual-links' defaults: _title: 'Contextual links example list objects' - _controller: '\Drupal\contextual_links_example\Controller\CLEController::cle_page' + _controller: '\Drupal\contextual_links_example\Controller\CLEController::clePage' requirements: _access: 'TRUE' @@ -20,7 +20,7 @@ contextual_links_example.contextual_links_object_view: path: 'examples/contextual-links/{entity_id}' defaults: _title: 'Contextual links example object' - _controller: '\Drupal\contextual_links_example\Controller\CLEController::cle_content' + _controller: '\Drupal\contextual_links_example\Controller\CLEController::cleContent' requirements: entity_id: \d+ _access: 'TRUE' diff --git a/contextual_links_example/src/Controller/CLEController.php b/contextual_links_example/src/Controller/CLEController.php index b9579aa..dc23231 100644 --- a/contextual_links_example/src/Controller/CLEController.php +++ b/contextual_links_example/src/Controller/CLEController.php @@ -5,12 +5,15 @@ namespace Drupal\contextual_links_example\Controller; use Drupal\contextual_links_example\Entity\CLEEntity; use Drupal\Core\Controller\ControllerBase; +/** + * Controller routines for contextual example routes. + */ class CLEController extends ControllerBase { /** * Returns a list of CLEEntity objects. */ - public function cle_page() { + public function clePage() { // For simplicity we hardcode an array of CLEEntity ids. $entity_ids = [1, 2, 3, 4, 5]; @@ -33,6 +36,7 @@ class CLEController extends ControllerBase { } /** + * Returns CLEEntity. * * @param int $entity_id * Entity ID. @@ -40,11 +44,11 @@ class CLEController extends ControllerBase { * @return array * An array as expected by drupal_render(). */ - public function cle_content(int $entity_id) { - $build = array( + public function cleContent(int $entity_id) { + $build = [ '#theme' => 'contextual_links_example_entity', '#object' => new CLEEntity(['id' => $entity_id], 'contextual_links_example_entity'), - ); + ]; return $build; } diff --git a/contextual_links_example/src/Entity/CLEEntity.php b/contextual_links_example/src/Entity/CLEEntity.php index 2b4dc97..090b8a0 100644 --- a/contextual_links_example/src/Entity/CLEEntity.php +++ b/contextual_links_example/src/Entity/CLEEntity.php @@ -28,9 +28,9 @@ class CLEEntity extends Entity { * Renderable array of the entity's body. */ public function bodyContent() { - return array( + return [ '#markup' => t('This is the content of example object @id.', ['@id' => $this->id()]), - ); + ]; } /** @@ -40,9 +40,9 @@ class CLEEntity extends Entity { * Renderable array of the entity's title. */ public function titleContent() { - return array( + return [ '#markup' => t('Title for example object @id', ['@id' => $this->id()]), - ); + ]; } } diff --git a/contextual_links_example/src/Form/CLEEntityEditForm.php b/contextual_links_example/src/Form/CLEEntityEditForm.php index 42107e8..cf4fca2 100644 --- a/contextual_links_example/src/Form/CLEEntityEditForm.php +++ b/contextual_links_example/src/Form/CLEEntityEditForm.php @@ -2,7 +2,6 @@ namespace Drupal\contextual_links_example\Form; - use Drupal\contextual_links_example\Entity\CLEEntity; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; @@ -24,6 +23,7 @@ class CLEEntityEditForm extends FormBase { * @param \Drupal\Core\Form\FormStateInterface $form_state * An associative array containing the current state of the form. * @param int $entity_id + * Entity ID. * * @return array * An associative array containing the robot add/edit form. diff --git a/contextual_links_example/src/Form/ContextualLinksExampleNodeActionForm.php b/contextual_links_example/src/Form/ContextualLinksExampleNodeActionForm.php index a4ea0ca..7592ca3 100644 --- a/contextual_links_example/src/Form/ContextualLinksExampleNodeActionForm.php +++ b/contextual_links_example/src/Form/ContextualLinksExampleNodeActionForm.php @@ -2,7 +2,6 @@ namespace Drupal\contextual_links_example\Form; - use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\node\NodeInterface; @@ -20,9 +19,9 @@ class ContextualLinksExampleNodeActionForm extends FormBase { /** * The form ID. Unique string identifying the form. * - * @see getFormID() - * * @var string + * + * @see getFormID() */ protected $formId = "contextual_links_example_node_action"; @@ -56,7 +55,7 @@ class ContextualLinksExampleNodeActionForm extends FormBase { * An associative array containing the structure of the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. - * @param \Drupal\node\NodeInterface + * @param \Drupal\node\NodeInterface $node * The node from the URL context. * * @return array @@ -117,7 +116,6 @@ class ContextualLinksExampleNodeActionForm extends FormBase { return $this->node->id(); } - /** * Returns the title of the current node. * diff --git a/contextual_links_example/src/Plugin/Block/CLEBlock.php b/contextual_links_example/src/Plugin/Block/CLEBlock.php index 98cfed6..f7d0d12 100644 --- a/contextual_links_example/src/Plugin/Block/CLEBlock.php +++ b/contextual_links_example/src/Plugin/Block/CLEBlock.php @@ -18,6 +18,7 @@ use Drupal\Core\Block\BlockBase; * ) */ class CLEBlock extends BlockBase { + /** * {@inheritdoc} */ diff --git a/contextual_links_example/src/Storage/CLEStorage.php b/contextual_links_example/src/Storage/CLEStorage.php index f14b53f..403ed1f 100644 --- a/contextual_links_example/src/Storage/CLEStorage.php +++ b/contextual_links_example/src/Storage/CLEStorage.php @@ -1,12 +1,7 @@ drupalCreateUser(['access contextual links', 'bypass node access', 'administer blocks']); + $web_user = $this->drupalCreateUser([ + 'access contextual links', + 'bypass node access', + 'administer blocks', + ]); // Login the admin user. $this->drupalLogin($web_user); @@ -48,7 +52,7 @@ class ContextualLinksExampleTest extends BrowserTestBase { /** * Test for a link to the contextual example in the Tools menu. */ - public function testContextualExampleLink(): void { + public function testContextualExampleLink() { $this->drupalGet(''); $this->assertSession()->linkByHrefExists('examples/contextual-links'); } @@ -56,7 +60,7 @@ class ContextualLinksExampleTest extends BrowserTestBase { /** * Tests contextual_links_example menus. */ - public function ContextualExampleMenu(): void { + public function testContextualExampleMenu() { $this->drupalGet('examples/contextual-links'); $this->assertSession()->statusCodeEquals(200); } @@ -64,7 +68,7 @@ class ContextualLinksExampleTest extends BrowserTestBase { /** * Tests contextual_links_example functionality. */ - public function testContextualLinksExampleBasic(): void { + public function testContextualLinksExampleBasic() { $assert = $this->assertSession(); $this->drupalGet('');