Commit 89ea2150 authored by Eric Bremner's avatar Eric Bremner
Browse files

Merge branch 'feature/ISTWCMS-4600-ibiki-content-links-dashboard' into '8.x-1.x'

Feature/istwcms 4600 ibiki content links dashboard

See merge request !4
parents 76ccf4cb 60522682
...@@ -3,9 +3,12 @@ ...@@ -3,9 +3,12 @@
namespace Drupal\uw_dashboard\Plugin\Block; namespace Drupal\uw_dashboard\Plugin\Block;
use Drupal\Core\Block\BlockBase; use Drupal\Core\Block\BlockBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\node\Entity\NodeType; use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\views\Views; use Drupal\views\Views;
use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Provides a 'ContentList' block. * Provides a 'ContentList' block.
...@@ -15,7 +18,65 @@ use Drupal\views\Views; ...@@ -15,7 +18,65 @@ use Drupal\views\Views;
* admin_label = @Translation("List content"), * admin_label = @Translation("List content"),
* ) * )
*/ */
class ContentListBlock extends BlockBase { class ContentListBlock extends BlockBase implements ContainerFactoryPluginInterface {
/**
* Current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $currentUser;
/**
* Entity type manager from the core.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* {@inheritdoc}
*/
public static function create(
ContainerInterface $container,
array $configuration,
$plugin_id,
$plugin_definition
) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('current_user'),
$container->get('entity_type.manager')
);
}
/**
* ContentManagementMenuBlock constructor.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Session\AccountProxyInterface $currentUser
* Current user.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* Entity type manager.
*/
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
AccountProxyInterface $currentUser,
EntityTypeManagerInterface $entityTypeManager
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->currentUser = $currentUser;
$this->entityTypeManager = $entityTypeManager;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
...@@ -46,8 +107,7 @@ class ContentListBlock extends BlockBase { ...@@ -46,8 +107,7 @@ class ContentListBlock extends BlockBase {
if (isset($this->configuration['display_my_content']) && $this->configuration['display_my_content']) { if (isset($this->configuration['display_my_content']) && $this->configuration['display_my_content']) {
// Add the current user to the arguments list. // Add the current user to the arguments list.
$arguments[] = \Drupal::currentUser()->id(); $arguments[] = $this->currentUser->id();
$arguments[] = \Drupal::currentUser()->id();
// Remove the author and last updated by exposed filter, // Remove the author and last updated by exposed filter,
// since we are only displaying the users content. // since we are only displaying the users content.
...@@ -118,7 +178,7 @@ class ContentListBlock extends BlockBase { ...@@ -118,7 +178,7 @@ class ContentListBlock extends BlockBase {
public function blockForm($form, FormStateInterface $form_state) { public function blockForm($form, FormStateInterface $form_state) {
// Get the node types. // Get the node types.
$node_types = NodeType::loadMultiple(); $node_types = $this->entityTypeManager->getStorage('node_type')->loadMultiple();
// Set the all options for options array. // Set the all options for options array.
$options = [ $options = [
......
...@@ -57,7 +57,11 @@ class ContentManagementMenuBlock extends BlockBase implements ContainerFactoryPl ...@@ -57,7 +57,11 @@ class ContentManagementMenuBlock extends BlockBase implements ContainerFactoryPl
// been configured. If not (else block) use secondary menu by // been configured. If not (else block) use secondary menu by
// default. // default.
if (isset($configured[$id])) { if (isset($configured[$id])) {
$selected_secondary = array_keys(array_filter($configured[$id] + $secondary_menu)); foreach ($secondary_menu as $key => $value) {
if (!empty($configured[$id][$key])) {
$selected_secondary[] = $key;
}
}
} }
else { else {
$selected_secondary = array_keys($secondary_menu); $selected_secondary = array_keys($secondary_menu);
...@@ -75,7 +79,7 @@ class ContentManagementMenuBlock extends BlockBase implements ContainerFactoryPl ...@@ -75,7 +79,7 @@ class ContentManagementMenuBlock extends BlockBase implements ContainerFactoryPl
'class' => ['content-management-block-table'], 'class' => ['content-management-block-table'],
], ],
'#headers' => [ '#headers' => [
$this->t($primary_menu_item->link->getTitle()), $primary_menu_item->link->getTitle(),
$this->t('Operations'), $this->t('Operations'),
], ],
]; ];
...@@ -98,10 +102,12 @@ class ContentManagementMenuBlock extends BlockBase implements ContainerFactoryPl ...@@ -98,10 +102,12 @@ class ContentManagementMenuBlock extends BlockBase implements ContainerFactoryPl
]; ];
foreach ($item->subtree as $sub_item) { foreach ($item->subtree as $sub_item) {
$build[$id]['table'][$sec_id]['operations']['#links'][$sub_item->link->getPluginId()] = [ if ($sub_item->access->isAllowed()) {
'title' => $this->t($sub_item->link->getTitle()), $build[$id]['table'][$sec_id]['operations']['#links'][$sub_item->link->getPluginId()] = [
'url' => $sub_item->link->getUrlObject(), 'title' => $sub_item->link->getTitle(),
]; 'url' => $sub_item->link->getUrlObject(),
];
}
} }
} }
} }
......
...@@ -3,8 +3,11 @@ ...@@ -3,8 +3,11 @@
namespace Drupal\uw_dashboard\Plugin\Block; namespace Drupal\uw_dashboard\Plugin\Block;
use Drupal\Core\Block\BlockBase; use Drupal\Core\Block\BlockBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\views\Views; use Drupal\views\Views;
use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Provides a 'WebformsList' block. * Provides a 'WebformsList' block.
...@@ -14,7 +17,53 @@ use Drupal\views\Views; ...@@ -14,7 +17,53 @@ use Drupal\views\Views;
* admin_label = @Translation("List forms"), * admin_label = @Translation("List forms"),
* ) * )
*/ */
class FormsListBlock extends BlockBase { class FormsListBlock extends BlockBase implements ContainerFactoryPluginInterface {
/**
* Entity type manager from the core.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* {@inheritdoc}
*/
public static function create(
ContainerInterface $container,
array $configuration,
$plugin_id,
$plugin_definition
) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('entity_type.manager')
);
}
/**
* ContentManagementMenuBlock constructor.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* Entity type manager.
*/
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
EntityTypeManagerInterface $entityTypeManager
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entityTypeManager;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
...@@ -72,7 +121,7 @@ class FormsListBlock extends BlockBase { ...@@ -72,7 +121,7 @@ class FormsListBlock extends BlockBase {
public function blockForm($form, FormStateInterface $form_state) { public function blockForm($form, FormStateInterface $form_state) {
// Get the category. // Get the category.
$categories = \Drupal::entityTypeManager()->getStorage('webform')->getCategories(FALSE); $categories = $this->entityTypeManager->getStorage('webform')->getCategories(FALSE);
// Set the all options for options array. // Set the all options for options array.
$options = [ $options = [
......
...@@ -3,12 +3,12 @@ description: 'Block placement for dashboard blocks and site management menu' ...@@ -3,12 +3,12 @@ description: 'Block placement for dashboard blocks and site management menu'
type: module type: module
core_version_requirement: '^8.8 || ^9' core_version_requirement: '^8.8 || ^9'
dependencies: dependencies:
- better_exposed_filters - drupal:better_exposed_filters
- config_views - drupal:config_views
- dashboards - drupal:dashboards
- layout_builder_restrictions - drupal:layout_builder_restrictions
- node - drupal:node
- system - drupal:system
- user - drupal:user
- views - drupal:views
- views_autocomplete_filters - drupal:views_autocomplete_filters
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment