diff --git a/config/install/views.view.uw_view_pub_authors.yml b/config/install/views.view.uw_view_pub_authors.yml index 39b33239214c3cdcefc3cd2cf7b32c096c7a0e84..eb82a148d42f25ca61aa24520e7c4e017a3f74cf 100644 --- a/config/install/views.view.uw_view_pub_authors.yml +++ b/config/install/views.view.uw_view_pub_authors.yml @@ -6,7 +6,7 @@ dependencies: - user - views_autocomplete_filters id: uw_view_pub_authors -label: 'Dashboard - publication reference authors' +label: 'Dashboard - Reference authors' module: views description: 'Find and manage contributors.' tag: default @@ -19,7 +19,7 @@ display: display_plugin: default position: 0 display_options: - title: 'Publication authors' + title: 'Reference authors' fields: leading_title: id: leading_title diff --git a/config/install/views.view.uw_view_pub_keywords.yml b/config/install/views.view.uw_view_pub_keywords.yml index 3ee991ce98edcf049ccc43a00a5533102ee7aab1..78e010e69fc1f3505c18956f88d36acfef7f1e16 100644 --- a/config/install/views.view.uw_view_pub_keywords.yml +++ b/config/install/views.view.uw_view_pub_keywords.yml @@ -6,10 +6,10 @@ dependencies: - user - views_autocomplete_filters id: uw_view_pub_keywords -label: 'Dashboard - publication reference keywords' +label: 'Dashboard - Reference keywords' module: views description: 'Find and manage keywords.' -tag: '' +tag: default base_table: bibcite_keyword base_field: id display: diff --git a/config/install/views.view.uw_view_pub_reference.yml b/config/install/views.view.uw_view_pub_reference.yml index 7be3ee33f89526ff183ddf6c1652270b31a6c7ed..82f4e851a3fc927dc5839c7681c2a4a4b5b86f66 100644 --- a/config/install/views.view.uw_view_pub_reference.yml +++ b/config/install/views.view.uw_view_pub_reference.yml @@ -6,7 +6,7 @@ dependencies: - user - views_autocomplete_filters id: uw_view_pub_reference -label: 'Dashboard - publication reference list' +label: 'Dashboard - Reference list' module: views description: 'Find and manage bibliographic references.' tag: default @@ -19,7 +19,7 @@ display: display_plugin: default position: 0 display_options: - title: Publications + title: References fields: bibcite_reference_bulk_form: id: bibcite_reference_bulk_form diff --git a/src/Plugin/Block/PublicationAuthorsBlock.php b/src/Plugin/Block/ReferenceAuthorsBlock.php similarity index 79% rename from src/Plugin/Block/PublicationAuthorsBlock.php rename to src/Plugin/Block/ReferenceAuthorsBlock.php index 8b45267b2f31855c422e248e344ddaefa2920800..708839d56c101d048ba33b62053f6710697af1a7 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 'Reference 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, @@ -54,7 +53,7 @@ class PublicationAuthorsBlock extends BlockBase implements ContainerFactoryPlugi } /** - * ContentManagementMenuBlock constructor. + * ReferenceAuthorsBlock constructor. * * @param array $configuration * A configuration array containing information about the plugin instance. @@ -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; @@ -95,8 +94,16 @@ class PublicationAuthorsBlock extends BlockBase implements ContainerFactoryPlugi /** @var \Drupal\views\ViewExecutable $view */ $view = $this->entityTypeManager ->getStorage('view') - ->load('uw_view_pub_authors') - ->getExecutable(); + ?->load('uw_view_pub_authors') + ?->getExecutable(); + + // In case something failed, like view not found, return an empty array + // before using view, to prevent call function on null errors. + if (!$view) { + return [ + '#markup' => $this->t('There was an error loading the block.'), + ]; + } // Set the display. $view->setDisplay('pub_reference_authors'); @@ -124,24 +131,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/PublicationReferenceBlock.php b/src/Plugin/Block/ReferenceBlock.php similarity index 79% rename from src/Plugin/Block/PublicationReferenceBlock.php rename to src/Plugin/Block/ReferenceBlock.php index 9b579cc4bf5f157bfd3318075807bf335d12c537..706b98c644ea802ff1e1d932a3597e0290ceebe8 100644 --- a/src/Plugin/Block/PublicationReferenceBlock.php +++ b/src/Plugin/Block/ReferenceBlock.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 'Reference' block. * * @Block( * id = "uw_publication_reference_block", - * admin_label = @Translation("Publication references"), + * admin_label = @Translation("References"), * ) */ -class PublicationReferenceBlock extends BlockBase implements ContainerFactoryPluginInterface { +class ReferenceBlock 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, @@ -54,7 +53,7 @@ class PublicationReferenceBlock extends BlockBase implements ContainerFactoryPlu } /** - * ContentManagementMenuBlock constructor. + * ReferenceBlock constructor. * * @param array $configuration * A configuration array containing information about the plugin instance. @@ -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; @@ -95,8 +94,16 @@ class PublicationReferenceBlock extends BlockBase implements ContainerFactoryPlu /** @var \Drupal\views\ViewExecutable $view */ $view = $this->entityTypeManager ->getStorage('view') - ->load('uw_view_pub_reference') - ->getExecutable(); + ?->load('uw_view_pub_reference') + ?->getExecutable(); + + // In case something failed, like view not found, return an empty array + // before using view, to prevent call function on null errors. + if (!$view) { + return [ + '#markup' => $this->t('There was an error loading the block.'), + ]; + } // Set the display. $view->setDisplay('pub_reference_list'); @@ -124,24 +131,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} */ diff --git a/src/Plugin/Block/PublicationKeywordsBlock.php b/src/Plugin/Block/ReferenceKeywordsBlock.php similarity index 77% rename from src/Plugin/Block/PublicationKeywordsBlock.php rename to src/Plugin/Block/ReferenceKeywordsBlock.php index 45febb2fadf7a46a20ec0464d6a5a9f09ad336f7..454f2f9a35eefbb758990528f983e8c528794a9b 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, @@ -54,7 +53,7 @@ class PublicationKeywordsBlock extends BlockBase implements ContainerFactoryPlug } /** - * ContentManagementMenuBlock constructor. + * ReferenceKeywordsBlock constructor. * * @param array $configuration * A configuration array containing information about the plugin instance. @@ -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.', ]; @@ -95,8 +94,16 @@ class PublicationKeywordsBlock extends BlockBase implements ContainerFactoryPlug /** @var \Drupal\views\ViewExecutable $view */ $view = $this->entityTypeManager ->getStorage('view') - ->load('uw_view_pub_keywords') - ->getExecutable(); + ?->load('uw_view_pub_keywords') + ?->getExecutable(); + + // In case something failed, like view not found, return an empty array + // before using view, to prevent call function on null errors. + if (!$view) { + return [ + '#markup' => $this->t('There was an error loading the block.'), + ]; + } // Set the display. $view->setDisplay('pub_reference_keywords'); @@ -124,29 +131,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/uw_dashboard.post_update.php b/uw_dashboard.post_update.php new file mode 100644 index 0000000000000000000000000000000000000000..ebb8b2708b18a83145169a465523808a1f4cd845 --- /dev/null +++ b/uw_dashboard.post_update.php @@ -0,0 +1,65 @@ +<?php + +/** + * @file + * Post update hooks for uw_dashboard module. + */ + +/** + * Renaming publications blocks titles to reference block titles. + */ +function uw_dashboard_post_update_blocks_rename(&$sandbox) { + $rename = [ + 'uw_publication_authors_block' => ['Publication reference authors' => 'Reference authors'], + 'uw_publication_reference_block' => ['Publication references' => 'References'], + 'uw_publication_keywords_block' => ['Publication reference keywords' => 'Reference keywords'], + 'uw_cbl_publication_search' => ['Publication reference search' => 'Reference search'], + ]; + + $database = \Drupal::database(); + + $query = $database->select('users_data', 'ud') + ->fields('ud', ['uid', 'value']) + ->condition('module', 'dashboards') + ->condition('name', 'my_dashboard'); + + $result = $query->execute()->fetchAllAssoc('uid'); + + \Drupal::logger('uw_dashboard') + ->info('Updating @num dashboards', ['@num' => count($result)]); + + /** @var \Drupal\user\UserDataInterface $dataService */ + $dataService = \Drupal::service('user.data'); + + foreach ($result as $uid => $row) { + try { + $data = unserialize($row->value, ['allowed_classes' => FALSE]); + $save_required = FALSE; + + foreach ($data as &$section) { + foreach ($section['components'] as &$block) { + if (array_key_exists($block['configuration']['id'], $rename)) { + $titles = $rename[$block['configuration']['id']]; + foreach ($titles as $old => $new) { + if (trim($block['configuration']['label']) === $old) { + $block['configuration']['label'] = $new; + $save_required = TRUE; + } + } + } + } + } + + if ($save_required) { + $dataService->set('dashboards', $uid, 'my_dashboard', serialize($data)); + } + } + catch (\Exception $ex) { + \Drupal::logger('uw_dashboard') + ->error('Block rename failed for user: @uid, with message: @message', [ + '@uid' => $uid, + '@message' => $ex->getMessage(), + ]); + } + } +}