Commit a78dbaec authored by Lily Yan's avatar Lily Yan
Browse files

Merge branch 'feature/coding-standards' into '8.x-1.x'

Coding standards

See merge request !2
parents 67ea1f90 373b1aca
<?php
namespace Drupal\uw_dashboard\Form;
use Drupal\Core\Block\BlockManagerInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class for blocks allowed on the dashboard.
*/
class AllowedBlocksForm extends ConfigFormBase {
const SETTINGS = 'uw_dashboard.allowed_blocks';
/** @var \Drupal\Core\Block\BlockManagerInterface */
/**
* The plugin manager block.
*
* @var \Drupal\Core\Block\BlockManagerInterface
*/
protected $blockManager;
/**
......@@ -28,13 +33,14 @@ class AllowedBlocksForm extends ConfigFormBase {
* UWDashboardBlockRestriction constructor.
*
* @param \Drupal\Core\Block\BlockManagerInterface $pluginManagerBlock
* The plugin manager block.
*/
public function __construct(BlockManagerInterface $pluginManagerBlock) {
$this->blockManager = $pluginManagerBlock;
}
/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
......@@ -43,14 +49,14 @@ class AllowedBlocksForm extends ConfigFormBase {
}
/**
* @inheritDoc
* {@inheritdoc}
*/
public function getFormId() {
return 'uw_dashboard_block_restrictions';
}
/**
* @inheritDoc
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$rows = [];
......@@ -85,7 +91,7 @@ class AllowedBlocksForm extends ConfigFormBase {
}
/**
* @inheritDoc
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$blocks = $form_state->getValue('allowed_blocks');
......
......@@ -101,7 +101,7 @@ class ContentListBlock extends BlockBase {
// Get the rendered title for the view.
$the_title_render_array = [
'#markup' => t('@title', ['@title' => $title]),
'#markup' => $this->t('@title', ['@title' => $title]),
'#allowed_tags' => ['h2'],
];
......@@ -163,11 +163,11 @@ class ContentListBlock extends BlockBase {
'#type' => 'select',
'#title' => $this->t('Sort by'),
'#options' => [
'title' => 'Title',
'type' => 'Content type',
'uid' => 'Author',
'revision_uid' => 'Last update by',
'changed' => 'Last updated',
'title' => $this->t('Title'),
'type' => $this->t('Content type'),
'uid' => $this->t('Author'),
'revision_uid' => $this->t('Last update by'),
'changed' => $this->t('Last updated'),
],
'#default_value' => isset($this->configuration['sort_by']) ? $this->configuration['sort_by'] : 'last_updated',
];
......@@ -177,8 +177,8 @@ class ContentListBlock extends BlockBase {
'#type' => 'select',
'#title' => $this->t('Sort order'),
'#options' => [
'asc' => 'Ascending',
'desc' => 'Descending',
'asc' => $this->t('Ascending'),
'desc' => $this->t('Descending'),
],
'#default_value' => isset($this->configuration['sort_order']) ? $this->configuration['sort_order'] : 'asc',
];
......
......@@ -9,9 +9,8 @@ use Drupal\Core\Menu\MenuTreeParameters;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class ContentManagementMenuBlock.
* Class for the content management menu block.
*
* @package Drupal\uw_dashboard\Plugin\Block
*
......@@ -22,11 +21,15 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
class ContentManagementMenuBlock extends BlockBase implements ContainerFactoryPluginInterface {
/** @var \Drupal\Core\Menu\MenuLinkTree */
/**
* The menu link tree.
*
* @var \Drupal\Core\Menu\MenuLinkTree
*/
protected $menuLinkTree;
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function build() {
$build = [];
......@@ -51,7 +54,8 @@ class ContentManagementMenuBlock extends BlockBase implements ContainerFactoryPl
if (!empty($secondary_menu)) {
// If sub menu exists for primary menu item, use it as default, but
// also append new menu items (items that are added after block has
// been configured. If not (else block) use secondary menu by default.
// been configured. If not (else block) use secondary menu by
// default.
if (isset($configured[$id])) {
$selected_secondary = array_keys(array_filter($configured[$id] + $secondary_menu));
}
......@@ -89,7 +93,7 @@ class ContentManagementMenuBlock extends BlockBase implements ContainerFactoryPl
];
$build[$id]['table'][$sec_id]['operations']['#links']['add'] = [
'title' => t('Add'),
'title' => $this->t('Add'),
'url' => $item->link->getUrlObject(),
];
......@@ -112,7 +116,7 @@ class ContentManagementMenuBlock extends BlockBase implements ContainerFactoryPl
}
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public static function create(
ContainerInterface $container,
......@@ -132,9 +136,13 @@ class ContentManagementMenuBlock extends BlockBase implements ContainerFactoryPl
* ContentManagementMenuBlock constructor.
*
* @param array $configuration
* @param $plugin_id
* @param $plugin_definition
* 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\Menu\MenuLinkTreeInterface $menuLinkTree
* The menu link tree.
*/
public function __construct(
array $configuration,
......@@ -147,7 +155,7 @@ class ContentManagementMenuBlock extends BlockBase implements ContainerFactoryPl
}
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function blockForm($form, FormStateInterface $form_state) {
$form['#attached']['library'][] = 'uw_dashboard/uw-styles';
......@@ -197,7 +205,7 @@ class ContentManagementMenuBlock extends BlockBase implements ContainerFactoryPl
}
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$menu_first_level = $this->getContentMenuItems();
......@@ -243,13 +251,13 @@ class ContentManagementMenuBlock extends BlockBase implements ContainerFactoryPl
/**
* Process menu tree, setting key to be plugin id, and value to be title.
*
* @param $tree
* @param array $tree
* Tree to be processed, access level checked.
*
* @return array
* Array where key is plugin id, and title is the value.
*/
protected function processMenuTree($tree) {
protected function processMenuTree(array $tree) {
$menu = [];
foreach ($tree as $menu_item) {
......
......@@ -55,7 +55,7 @@ class FormsListBlock extends BlockBase {
// Get the rendered title for the view.
$the_title_render_array = [
'#markup' => t('@title', ['@title' => $title]),
'#markup' => $this->t('@title', ['@title' => $title]),
'#allowed_tags' => ['h2'],
];
......@@ -107,7 +107,6 @@ class FormsListBlock extends BlockBase {
// '#default_value' => $this->configuration['display_my_forms'] ?? 'no',
// ];
// @endcode
return $form;
}
......
......@@ -10,7 +10,7 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class UwDblSiteManagement
* Class UwDblSiteManagement.
*
* @package Drupal\uw_site_management\Plugin\Block
*
......@@ -21,11 +21,15 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
class SiteManagementMenuBlock extends BlockBase implements ContainerFactoryPluginInterface {
/** @var \Drupal\Core\Menu\MenuLinkTree */
/**
* The menu link tree.
*
* @var \Drupal\Core\Menu\MenuLinkTree
*/
protected $menuLinkTree;
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function build() {
$links = [];
......@@ -45,7 +49,7 @@ class SiteManagementMenuBlock extends BlockBase implements ContainerFactoryPlugi
}
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public static function create(
ContainerInterface $container,
......@@ -65,9 +69,13 @@ class SiteManagementMenuBlock extends BlockBase implements ContainerFactoryPlugi
* UwDblSiteManagement constructor.
*
* @param array $configuration
* @param $plugin_id
* @param $plugin_definition
* 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\Menu\MenuLinkTreeInterface $menuLinkTree
* The menu link tree.
*/
public function __construct(
array $configuration,
......@@ -80,7 +88,7 @@ class SiteManagementMenuBlock extends BlockBase implements ContainerFactoryPlugi
}
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function blockForm($form, FormStateInterface $form_state) {
$menu_items = $this->getMenuItems();
......@@ -104,7 +112,7 @@ class SiteManagementMenuBlock extends BlockBase implements ContainerFactoryPlugi
}
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$menus = $form_state->getValue('selected_menus');
......
......@@ -7,7 +7,7 @@ use Drupal\layout_builder_restrictions\Plugin\LayoutBuilderRestriction\EntityVie
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* UwDashboardRestrictBlocksLayouts class.
* Class for restricting blocks/layouts for UW dashboard.
*
* @LayoutBuilderRestriction(
* id = "uw_dashboard_restrict_blocks_layouts",
......@@ -17,11 +17,15 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
class UwDashboardRestrictBlocksLayouts extends EntityViewModeRestriction {
/** @var \Drupal\Core\Config\ConfigFactoryInterface */
/**
* Config factory to load blocks allowed to be displayed on dashboard.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* @inheritDoc
* {@inheritdoc}
*/
public static function create(
ContainerInterface $container,
......@@ -62,7 +66,7 @@ class UwDashboardRestrictBlocksLayouts extends EntityViewModeRestriction {
}
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function alterBlockDefinitions(array $definitions, array $context) {
......@@ -93,7 +97,14 @@ class UwDashboardRestrictBlocksLayouts extends EntityViewModeRestriction {
if ($context['section_storage']->pluginId == 'dashboards' || $context['section_storage']->pluginId == 'dashboards_override') {
// The allowed layouts machine names.
$allowed_layouts = ['layout_1', 'uw_1_column', 'uw_2_column', 'uw_3_column','uw_inverted_l_left', 'uw_inverted_l_right'];
$allowed_layouts = [
'layout_1',
'uw_1_column',
'uw_2_column',
'uw_3_column',
'uw_inverted_l_left',
'uw_inverted_l_right',
];
// Step through each of the definitions and unset anything
// that is not in the allowed layouts array.
......@@ -110,4 +121,5 @@ class UwDashboardRestrictBlocksLayouts extends EntityViewModeRestriction {
return $definitions;
}
}
name: 'Dashboard items'
description: 'Block placement for dashboard blocks and site management menu'
type: module
core_version_requirement: ^8 || ^9
core_version_requirement: '^8.8 || ^9'
dependencies:
- better_exposed_filters
- config_views
- dashboards
- layout_builder_restrictions
- node
- system
- user
- views
- views_autocomplete_filters
- layout_builder_restrictions
Markdown is supported
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