Skip to content
Snippets Groups Projects
Commit de24c91d authored by Himanshu  Jhaloya's avatar Himanshu Jhaloya Committed by Damien McKenna
Browse files

Issue #3325935 by himanshu_jhaloya, DamienMcKenna, samit.310@gmail.com: Drupal...

Issue #3325935 by himanshu_jhaloya, DamienMcKenna, samit.310@gmail.com: Drupal coding standards issues.
parent 53accf19
No related branches found
Tags 8.x-3.6
No related merge requests found
......@@ -14,7 +14,7 @@ class TaxonomyMenu extends ControllerBase {
/**
* Render taxonomy links.
*
* @return string
* @return string[]
* Return Hello string.
*/
public function renderTaxonomyLinks() {
......@@ -29,10 +29,7 @@ class TaxonomyMenu extends ControllerBase {
$links += $taxonomy_menu->getLinks([]);
}
return [
'#type' => 'markup',
'#markup' => '',
];
return $links;
}
}
......@@ -145,7 +145,7 @@ class TaxonomyMenu extends ConfigEntityBase implements TaxonomyMenuInterface {
* True or false.
*/
public function useTermWeightOrder() {
return isset($this->use_term_weight_order) ? $this->use_term_weight_order : TRUE;
return $this->use_term_weight_order ?? TRUE;
}
/**
......@@ -196,7 +196,7 @@ class TaxonomyMenu extends ConfigEntityBase implements TaxonomyMenuInterface {
* {@inheritdoc}
*/
public function getLinks(array $base_plugin_definition = [], $include_base_plugin_id = FALSE) {
/* @var $termStorage \Drupal\taxonomy\TermStorageInterface */
/** @var \Drupal\taxonomy\TermStorageInterface $termStorage */
$termStorage = $this->entityTypeManager()->getStorage('taxonomy_term');
// Load taxonomy terms for tax menu vocab.
$terms = $termStorage->loadTree($this->getVocabulary(), 0, $this->getDepth() + 1);
......@@ -256,10 +256,10 @@ class TaxonomyMenu extends ConfigEntityBase implements TaxonomyMenuInterface {
$menu_id = $this->getMenu();
// Determine parent link.
// TODO:
// Evaluate use case of multiple parents (should we make many menu items?)
// @todo Evaluate use case of multiple parents
// (should we make many menu items?)
$menu_parent_id = NULL;
/* @var $termStorage \Drupal\taxonomy\TermStorageInterface */
/** @var \Drupal\taxonomy\TermStorageInterface $termStorage */
$termStorage = $this->entityTypeManager()->getStorage('taxonomy_term');
$parents = $termStorage->loadParents($term_id);
$parents = array_values($parents);
......@@ -274,7 +274,7 @@ class TaxonomyMenu extends ConfigEntityBase implements TaxonomyMenuInterface {
$menu_parent_id = str_replace($this->getMenu() . ':', '', $this->getMenuParent());
}
// TODO: Consider implementing a forced weight based on taxonomy tree.
// @todo Consider implementing a forced weight based on taxonomy tree.
// Generate link.
$arguments = ['taxonomy_term' => $term_id];
......
......@@ -4,7 +4,6 @@ namespace Drupal\taxonomy_menu\Form;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\system\Entity\Menu;
use Drupal\Core\Menu\MenuParentFormSelector;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityFieldManager;
......@@ -153,7 +152,7 @@ class TaxonomyMenuForm extends EntityForm {
];
// Menu selection.
$custom_menus = Menu::loadMultiple();
$custom_menus = $this->entityTypeManager->getStorage('menu')->loadMultiple();
foreach ($custom_menus as $menu_name => $menu) {
$custom_menus[$menu_name] = $menu->label();
}
......@@ -175,7 +174,7 @@ class TaxonomyMenuForm extends EntityForm {
$form['use_term_weight_order'] = [
'#type' => 'checkbox',
'#title' => $this->t('Use term weight order'),
'#default_value' => isset($taxonomy_menu->use_term_weight_order) ? $taxonomy_menu->use_term_weight_order : TRUE,
'#default_value' => $taxonomy_menu->use_term_weight_order ?? TRUE,
];
return $form;
......
......@@ -45,12 +45,12 @@ class TaxonomyMenuMenuLink extends DeriverBase implements ContainerDeriverInterf
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$links = [];
/* @var $taxonomy_menus \Drupal\taxonomy_menu\TaxonomyMenuInterface[] */
/** @var \Drupal\taxonomy_menu\TaxonomyMenuInterface[] $taxonomy_menus */
$taxonomy_menus = $this->taxonomyMenuStorage->loadMultiple();
// MenuLinkContent entity, menulinkcontent table, look for data.
foreach ($taxonomy_menus as $taxonomy_menu) {
/* @var $taxonomy_menu \Drupal\taxonomy_menu\TaxonomyMenuInterface */
/** @var \Drupal\taxonomy_menu\TaxonomyMenuInterface $taxonomy_menu */
$taxonomy_menu->getMenu();
$links = array_merge($links, $taxonomy_menu->getLinks($base_plugin_definition));
}
......
......@@ -96,7 +96,7 @@ class TaxonomyMenuHelper {
// Load relevant taxonomy menus.
$tax_menus = $this->getTermMenusByVocabulary($term->bundle());
/* @var $menu \Drupal\taxonomy_menu\TaxonomyMenuInterface */
/** @var \Drupal\taxonomy_menu\TaxonomyMenuInterface $menu */
foreach ($tax_menus as $menu) {
$links = $menu->getLinks([], TRUE);
......@@ -135,7 +135,7 @@ class TaxonomyMenuHelper {
public function removeTaxonomyMenuEntries(TermInterface $term, $rebuild_all = TRUE) {
// Load relevant taxonomy menus.
$tax_menus = $this->getTermMenusByVocabulary($term->bundle());
/* @var $menu \Drupal\taxonomy_menu\TaxonomyMenuInterface */
/** @var \Drupal\taxonomy_menu\TaxonomyMenuInterface $menu */
foreach ($tax_menus as $menu) {
// Remove all links.
if ($rebuild_all) {
......
......@@ -10,6 +10,7 @@ use Drupal\Tests\BrowserTestBase;
* @group taxonomy_menu
*/
class TaxonomyMenuOperationsTest extends BrowserTestBase {
/**
* List of modules.
*
......@@ -31,7 +32,10 @@ class TaxonomyMenuOperationsTest extends BrowserTestBase {
parent::setUp();
// Create user with permission to create policy.
$user1 = $this->drupalCreateUser(['administer site configuration', 'administer taxonomy']);
$user1 = $this->drupalCreateUser([
'administer site configuration',
'administer taxonomy',
]);
$this->drupalLogin($user1);
// Create a testing taxonomy vocabulary.
......@@ -41,7 +45,7 @@ class TaxonomyMenuOperationsTest extends BrowserTestBase {
'vid' => 'test_tax_vocab',
'name' => 'Test',
];
$this->submitForm($edit, t('Save'));
$this->submitForm($edit, 'Save');
// Create logged in user.
$perms = [
......@@ -57,20 +61,20 @@ class TaxonomyMenuOperationsTest extends BrowserTestBase {
$edit = [
'name[0][value]' => 'test term 1',
];
$this->submitForm($edit, t('Save'));
$this->submitForm($edit, 'Save');
$this->drupalGet('admin/structure/taxonomy/manage/test_tax_vocab/add');
$edit = [
'name[0][value]' => 'test term 1-A',
'parent[]' => '1',
];
$this->submitForm($edit, t('Save'));
$this->submitForm($edit, 'Save');
$this->drupalGet('admin/structure/taxonomy/manage/test_tax_vocab/add');
$edit = [
'name[0][value]' => 'test term 2',
];
$this->submitForm($edit, t('Save'));
$this->submitForm($edit, 'Save');
// Create a testing menu.
$this->drupalGet('admin/structure/menu/add');
......@@ -78,7 +82,7 @@ class TaxonomyMenuOperationsTest extends BrowserTestBase {
'id' => 'test-menu',
'label' => 'Test',
];
$this->submitForm($edit, t('Save'));
$this->submitForm($edit, 'Save');
// Create new taxonomy menu.
$this->drupalGet('admin/structure/taxonomy_menu/add');
......@@ -91,7 +95,7 @@ class TaxonomyMenuOperationsTest extends BrowserTestBase {
'depth' => '1',
'menu_parent' => 'test-menu:',
];
$this->submitForm($edit, t('Save'));
$this->submitForm($edit, 'Save');
}
/**
......@@ -101,24 +105,25 @@ class TaxonomyMenuOperationsTest extends BrowserTestBase {
// Check menu for taxonomy-based menu items keyed 1, 2, and 3.
$this->drupalGet('admin/structure/menu/manage/test-menu');
// We should expect to see enabled field for taxonomy term 1
// We should expect to see enabled field for taxonomy term 1.
$this->assertSession()->fieldExists(
'links[menu_plugin_id:taxonomy_menu.menu_link:taxonomy_menu.menu_link.test_tax_menu.1][enabled]'
);
// We should expect to see enabled field for taxonomy term 2
// We should expect to see enabled field for taxonomy term 2.
$this->assertSession()->fieldExists(
'links[menu_plugin_id:taxonomy_menu.menu_link:taxonomy_menu.menu_link.test_tax_menu.2][enabled]'
);
// We should expect to see enabled field for taxonomy term 3
// We should expect to see enabled field for taxonomy term 3.
$this->assertSession()->fieldExists(
'links[menu_plugin_id:taxonomy_menu.menu_link:taxonomy_menu.menu_link.test_tax_menu.3][enabled]'
);
// Check 2 is a parent of 1.
$this->drupalGet('admin/structure/menu/link/taxonomy_menu.menu_link:taxonomy_menu.menu_link.test_tax_menu.2/edit');
// We should expect to see taxonomy term 2 have a parent of taxonomy term 1'
// We should expect to see taxonomy term 2 have a parent
// of taxonomy term 1'.
$this->assertSession()->fieldExists(
'menu_parent'
);
......@@ -138,11 +143,11 @@ class TaxonomyMenuOperationsTest extends BrowserTestBase {
$edit = [
'name[0][value]' => 'test term 3',
];
$this->submitForm($edit, t('Save'));
$this->submitForm($edit, 'Save');
$this->drupalGet('admin/structure/menu/manage/test-menu');
// Check for it within the menu.
// We should expect to see enabled field for taxonomy term 4
// We should expect to see enabled field for taxonomy term 4.
$this->assertSession()->fieldExists(
'links[menu_plugin_id:taxonomy_menu.menu_link:taxonomy_menu.menu_link.test_tax_menu.3][enabled]'
);
......@@ -155,10 +160,10 @@ class TaxonomyMenuOperationsTest extends BrowserTestBase {
// Delete a term.
$this->drupalGet('taxonomy/term/3/delete');
$edit = [];
$this->submitForm($edit, t('Delete'));
$this->submitForm($edit, 'Delete');
// Check for it within the menu.
// We should not expect to see enabled field for taxonomy term 3
// We should not expect to see enabled field for taxonomy term 3.
$this->assertSession()->fieldNotExists(
'enabled'
);
......@@ -169,7 +174,7 @@ class TaxonomyMenuOperationsTest extends BrowserTestBase {
*/
public function testTaxMenuLinkExpanded() {
$this->drupalGet('admin/structure/menu/link/taxonomy_menu.menu_link:taxonomy_menu.menu_link.test_tax_menu.1/edit');
// We should expect to see expanded value for menu based on taxonomy term 1
// We should expect to see expanded value for menu based on taxonomy term 1.
$this->assertSession()->fieldValueEquals(
'expanded',
1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment