From 19f62046e7aee511a06287dffe69a4e7f152b3a2 Mon Sep 17 00:00:00 2001 From: Igor Biki <ibiki@uwaterloo.ca> Date: Tue, 25 Feb 2025 14:21:41 -0500 Subject: [PATCH] ISTWCMS-7275: Refactor block classes to rename and streamline logic. Renamed block classes and labels for consistency: Keywords, References, and Authors blocks now reflect updated naming conventions. Removed redundant block form and submit methods to simplify code. Adjusted permissions to align with new keyword editing logic. --- ...orsBlock.php => ReferenceAuthorsBlock.php} | 33 ++++------------- ...dsBlock.php => ReferenceKeywordsBlock.php} | 37 +++++-------------- ...ReferenceBlock.php => ReferencesBlock.php} | 33 ++++------------- 3 files changed, 23 insertions(+), 80 deletions(-) rename src/Plugin/Block/{PublicationAuthorsBlock.php => ReferenceAuthorsBlock.php} (82%) rename src/Plugin/Block/{PublicationKeywordsBlock.php => ReferenceKeywordsBlock.php} (79%) rename src/Plugin/Block/{PublicationReferenceBlock.php => ReferencesBlock.php} (82%) diff --git a/src/Plugin/Block/PublicationAuthorsBlock.php b/src/Plugin/Block/ReferenceAuthorsBlock.php similarity index 82% rename from src/Plugin/Block/PublicationAuthorsBlock.php rename to src/Plugin/Block/ReferenceAuthorsBlock.php index 8b45267..b0ed3dd 100644 --- a/src/Plugin/Block/PublicationAuthorsBlock.php +++ b/src/Plugin/Block/ReferenceAuthorsBlock.php @@ -5,35 +5,34 @@ namespace Drupal\uw_dashboard\Plugin\Block; use Drupal\Core\Access\AccessResult; use Drupal\Core\Block\BlockBase; use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountProxyInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** - * Provides a 'Publication reference authors' block. + * Provides a 'References authors' block. * * @Block( * id = "uw_publication_authors_block", - * admin_label = @Translation("Publication reference authors"), + * admin_label = @Translation("Reference authors"), * ) */ -class PublicationAuthorsBlock extends BlockBase implements ContainerFactoryPluginInterface { +class ReferenceAuthorsBlock extends BlockBase implements ContainerFactoryPluginInterface { /** * Entity type manager from the core. * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ - protected $entityTypeManager; + protected EntityTypeManagerInterface $entityTypeManager; /** * The current user. * * @var \Drupal\Core\Session\AccountProxyInterface */ - protected $currentUser; + protected AccountProxyInterface $currentUser; /** * {@inheritdoc} @@ -42,7 +41,7 @@ class PublicationAuthorsBlock extends BlockBase implements ContainerFactoryPlugi ContainerInterface $container, array $configuration, $plugin_id, - $plugin_definition + $plugin_definition, ) { return new static( $configuration, @@ -72,7 +71,7 @@ class PublicationAuthorsBlock extends BlockBase implements ContainerFactoryPlugi $plugin_id, $plugin_definition, EntityTypeManagerInterface $entityTypeManager, - AccountProxyInterface $currentUser + AccountProxyInterface $currentUser, ) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->entityTypeManager = $entityTypeManager; @@ -124,24 +123,6 @@ class PublicationAuthorsBlock extends BlockBase implements ContainerFactoryPlugi ]; } - /** - * {@inheritdoc} - */ - public function blockForm($form, FormStateInterface $form_state) { - - // Get the parent form. - $form = parent::blockForm($form, $form_state); - - return $form; - } - - /** - * {@inheritdoc} - */ - public function blockSubmit($form, FormStateInterface $form_state) { - - } - /** * {@inheritdoc} */ diff --git a/src/Plugin/Block/PublicationKeywordsBlock.php b/src/Plugin/Block/ReferenceKeywordsBlock.php similarity index 79% rename from src/Plugin/Block/PublicationKeywordsBlock.php rename to src/Plugin/Block/ReferenceKeywordsBlock.php index 45febb2..351c932 100644 --- a/src/Plugin/Block/PublicationKeywordsBlock.php +++ b/src/Plugin/Block/ReferenceKeywordsBlock.php @@ -5,35 +5,34 @@ namespace Drupal\uw_dashboard\Plugin\Block; use Drupal\Core\Access\AccessResult; use Drupal\Core\Block\BlockBase; use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountProxyInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** - * Provides a 'Publication reference keywords' block. + * Provides a 'Reference keywords' block. * * @Block( * id = "uw_publication_keywords_block", - * admin_label = @Translation("Publication reference keywords"), + * admin_label = @Translation("Reference keywords"), * ) */ -class PublicationKeywordsBlock extends BlockBase implements ContainerFactoryPluginInterface { +class ReferenceKeywordsBlock extends BlockBase implements ContainerFactoryPluginInterface { /** * Entity type manager from the core. * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ - protected $entityTypeManager; + protected EntityTypeManagerInterface $entityTypeManager; /** * The current user. * * @var \Drupal\Core\Session\AccountProxyInterface */ - protected $currentUser; + protected AccountProxyInterface $currentUser; /** * {@inheritdoc} @@ -42,7 +41,7 @@ class PublicationKeywordsBlock extends BlockBase implements ContainerFactoryPlug ContainerInterface $container, array $configuration, $plugin_id, - $plugin_definition + $plugin_definition, ) { return new static( $configuration, @@ -72,7 +71,7 @@ class PublicationKeywordsBlock extends BlockBase implements ContainerFactoryPlug $plugin_id, $plugin_definition, EntityTypeManagerInterface $entityTypeManager, - AccountProxyInterface $currentUser + AccountProxyInterface $currentUser, ) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->entityTypeManager = $entityTypeManager; @@ -85,7 +84,7 @@ class PublicationKeywordsBlock extends BlockBase implements ContainerFactoryPlug public function build() { // Add a message if the user does not have access to the block. - if (!$this->currentUser->hasPermission('edit bibcite_contributor')) { + if (!$this->currentUser->hasPermission('edit bibcite_keyword')) { return [ '#markup' => 'You do not have permission to view this block.', ]; @@ -124,29 +123,11 @@ class PublicationKeywordsBlock extends BlockBase implements ContainerFactoryPlug ]; } - /** - * {@inheritdoc} - */ - public function blockForm($form, FormStateInterface $form_state) { - - // Get the parent form. - $form = parent::blockForm($form, $form_state); - - return $form; - } - - /** - * {@inheritdoc} - */ - public function blockSubmit($form, FormStateInterface $form_state) { - - } - /** * {@inheritdoc} */ protected function blockAccess(AccountInterface $account) { - return AccessResult::allowedIfHasPermission($account, 'edit bibcite_contributor'); + return AccessResult::allowedIfHasPermission($account, 'edit bibcite_keyword'); } } diff --git a/src/Plugin/Block/PublicationReferenceBlock.php b/src/Plugin/Block/ReferencesBlock.php similarity index 82% rename from src/Plugin/Block/PublicationReferenceBlock.php rename to src/Plugin/Block/ReferencesBlock.php index 9b579cc..a5b85da 100644 --- a/src/Plugin/Block/PublicationReferenceBlock.php +++ b/src/Plugin/Block/ReferencesBlock.php @@ -5,35 +5,34 @@ namespace Drupal\uw_dashboard\Plugin\Block; use Drupal\Core\Access\AccessResult; use Drupal\Core\Block\BlockBase; use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountProxyInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** - * Provides a 'Publication reference' block. + * Provides a 'References' block. * * @Block( * id = "uw_publication_reference_block", - * admin_label = @Translation("Publication references"), + * admin_label = @Translation("References"), * ) */ -class PublicationReferenceBlock extends BlockBase implements ContainerFactoryPluginInterface { +class ReferencesBlock extends BlockBase implements ContainerFactoryPluginInterface { /** * Entity type manager from the core. * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ - protected $entityTypeManager; + protected EntityTypeManagerInterface $entityTypeManager; /** * The current user. * * @var \Drupal\Core\Session\AccountProxyInterface */ - protected $currentUser; + protected AccountProxyInterface $currentUser; /** * {@inheritdoc} @@ -42,7 +41,7 @@ class PublicationReferenceBlock extends BlockBase implements ContainerFactoryPlu ContainerInterface $container, array $configuration, $plugin_id, - $plugin_definition + $plugin_definition, ) { return new static( $configuration, @@ -72,7 +71,7 @@ class PublicationReferenceBlock extends BlockBase implements ContainerFactoryPlu $plugin_id, $plugin_definition, EntityTypeManagerInterface $entityTypeManager, - AccountProxyInterface $currentUser + AccountProxyInterface $currentUser, ) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->entityTypeManager = $entityTypeManager; @@ -124,24 +123,6 @@ class PublicationReferenceBlock extends BlockBase implements ContainerFactoryPlu ]; } - /** - * {@inheritdoc} - */ - public function blockForm($form, FormStateInterface $form_state) { - - // Get the parent form. - $form = parent::blockForm($form, $form_state); - - return $form; - } - - /** - * {@inheritdoc} - */ - public function blockSubmit($form, FormStateInterface $form_state) { - - } - /** * {@inheritdoc} */ -- GitLab