Skip to content

Commit

Permalink
Update composer, render and services.md
Browse files Browse the repository at this point in the history
  • Loading branch information
selwynpolit committed Jun 28, 2024
1 parent 635b4e7 commit 4d332f7
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 16 deletions.
33 changes: 17 additions & 16 deletions book/composer.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,25 @@ Create the patch:
git diff >file_entity_disable_file_menu_tab.patch
```

Add the patch to the patches section of composer.json. Notice below the line starting with \"drupal/file_entity\" is the local file patch:
Add the patch to the `patches` section of `composer.json` under the `extra` section. Notice below the line starting with `"drupal/file_entity\"` is the local file patch:

```json
"patches": {
"drupal/commerce": {
"Allow order types to have no carts": "https://www.drupal.org/files/issues/2018-03-16/commerce-direct-checkout-50.patch"
},
"drupal/views_load_more": {
"Template change to keep up with core": "https://www.drupal.org/files/issues/views-load-more-pager-class-2543714-02.patch" ,
"Problems with exposed filters": "https://www.drupal.org/files/issues/views_load_more-problems-with-exposed-filters-2630306-4.patch"
},
"drupal/easy_breadcrumb": {
"Titles in breadcrumbs are double-escaped": "https://www.drupal.org/files/issues/2018-06-21/2979389-7-easy-breadcrumb--double-escaped-titles.patch"
},
"drupal/file_entity": {
"Temporarily disable the files menu tab": "./patches/file_entity_disable_file_menu_tab.patch"
}
}
"extra": {
"patches": {
"drupal/file_entity": {
"Temporarily disable the files menu tab": "./patches/file_entity_disable_file_menu_tab.patch"
}
"drupal/commerce": {
"Allow order types to have no carts": "https://www.drupal.org/files/issues/2018-03-16/commerce-direct-checkout-50.patch"
},
"drupal/views_load_more": {
"Template change to keep up with core": "https://www.drupal.org/files/issues/views-load-more-pager-class-2543714-02.patch" ,
"Problems with exposed filters": "https://www.drupal.org/files/issues/views_load_more-problems-with-exposed-filters-2630306-4.patch"
},
"drupal/easy_breadcrumb": {
"Titles in breadcrumbs are double-escaped": "https://www.drupal.org/files/issues/2018-06-21/2979389-7-easy-breadcrumb--double-escaped-titles.patch"
},
}
```

Revert the file in git and then try to apply the patch.
Expand Down
85 changes: 85 additions & 0 deletions book/render.md
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,91 @@ public function videoSelectChange(array $form, FormStateInterface $form_state) {
}
```

## Table of menu items

This emulates the Drupal core menu listing with the menu items in a table with the columns: `Title`, `Description`, and `Operations` and is used in the `build()` function of a block:

```php
/**
* {@inheritdoc}
*/
public function build(): array {
$uid = $this->currentUser->id();
$user = $this->entityTypeManager->getStorage('user')->load($uid);

// Load all menus.
$menus = $this->menuStorage->loadMultiple();
$accessible_menus = [];

foreach ($menus as $menu) {
$menu_name = $menu->id();
$parameters = $this->menuLinkTree->getCurrentRouteMenuTreeParameters($menu_name);
$tree = $this->menuLinkTree->load($menu_name, $parameters);
$manipulators = [
['callable' => 'menu.default_tree_manipulators:checkAccess'],
['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
];
$tree = $this->menuLinkTree->transform($tree, $manipulators);

$menu_entity = $this->entityTypeManager->getStorage('menu')
->load($menu_name);
$access = $this->checkSections($menu_entity, $user);
if ($access) {
$edit_url = Url::fromRoute('entity.menu.edit_form', ['menu' => $menu_name]);
$add_link_url = Url::fromRoute('entity.menu.add_link_form', ['menu' => $menu_name]);

$rows[] = [
'title' => $menu->label(),
'description' => $menu->getDescription(),
'operations' => [
'data' => [
'#type' => 'operations',
'#links' => [
'edit' => [
'title' => $this->t('Edit'),
'url' => $edit_url,
],
'add_link' => [
'title' => $this->t('Add link'),
'url' => $add_link_url,
],
],
],
],
];

}
}

$build['content'] = [
'#type' => 'table',
'#header' => [$this->t('Title'), $this->t('Description'), $this->t('Operations')],
'#rows' => $rows,
'#empty' => $this->t('No menus available.'),
];

return $build;
}
```

If you just want a list of links, you can use the following code:

```php
//...
if ($access) {
$url = Url::fromRoute('entity.menu.edit_form', ['menu' => $menu_name]);
$link = Link::fromTextAndUrl($menu->label(), $url)->toRenderable();
$accessible_menus[] = $link;
//...

$build['content'] = [
'#theme' => 'item_list',
'#items' => $accessible_menus,
];
return $build;



## Limit allowed tags in markup

Here we allow \<i\> (italics) tags in the login menu item, and \<i\> and \<sup\> (superscript) tags in the logout menu item
Expand Down
2 changes: 2 additions & 0 deletions book/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,9 @@ $this->account = $account;

See more about [Dependency injection in Drupal 8 plugins (or blocks) by Märt Matoo - March 2017](https://chromatichq.com/insights/dependency-injection-drupal-8-plugins/)

## List all services using Devel module

You can use the devel menu and select Container Info or navigate to `/devel/container/service` to see a list of all services.


## List all services using Drush
Expand Down

0 comments on commit 4d332f7

Please sign in to comment.