Issue #1903750 by benjy: Convert menu_link() hooks to use Type-Hinting.

8.0.x
catch 2013-03-04 15:28:39 +00:00
parent f8899fb67b
commit e1fa73eaf4
3 changed files with 15 additions and 12 deletions

View File

@ -47,7 +47,7 @@ function hook_menu_link_load($menu_links) {
*
* @see hook_menu_link_load()
*/
function hook_menu_link_presave($menu_link) {
function hook_menu_link_presave(\Drupal\menu_link\Plugin\Core\Entity\MenuLink $menu_link) {
// Make all new admin links hidden (a.k.a disabled).
if (strpos($menu_link->link_path, 'admin') === 0 && $menu_link->isNew()) {
$menu_link->hidden = 1;
@ -78,7 +78,7 @@ function hook_menu_link_presave($menu_link) {
* @see hook_menu_link_update()
* @see hook_menu_link_delete()
*/
function hook_menu_link_insert($menu_link) {
function hook_menu_link_insert(\Drupal\menu_link\Plugin\Core\Entity\MenuLink $menu_link) {
// In our sample case, we track menu items as editing sections
// of the site. These are stored in our table as 'disabled' items.
$record['mlid'] = $menu_link->id();
@ -101,7 +101,7 @@ function hook_menu_link_insert($menu_link) {
* @see hook_menu_link_insert()
* @see hook_menu_link_delete()
*/
function hook_menu_link_update($menu_link) {
function hook_menu_link_update(\Drupal\menu_link\Plugin\Core\Entity\MenuLink $menu_link) {
// If the parent menu has changed, update our record.
$menu_name = db_query("SELECT menu_name FROM {menu_example} WHERE mlid = :mlid", array(':mlid' => $menu_link->id()))->fetchField();
if ($menu_name != $menu_link->menu_name) {
@ -126,7 +126,7 @@ function hook_menu_link_update($menu_link) {
* @see hook_menu_link_insert()
* @see hook_menu_link_update()
*/
function hook_menu_link_delete($menu_link) {
function hook_menu_link_delete(\Drupal\menu_link\Plugin\Core\Entity\MenuLink $menu_link) {
// Delete the record from our table.
db_delete('menu_example')
->condition('mlid', $menu_link->id())

View File

@ -5,6 +5,8 @@
* Dummy module implementing hook menu.
*/
use Drupal\menu_link\Plugin\Core\Entity\MenuLink;
/**
* Implements hook_menu().
*/
@ -594,7 +596,7 @@ function menu_test_menu_name($new_name = '') {
* @return
* A random string.
*/
function menu_test_menu_link_insert($item) {
function menu_test_menu_link_insert(MenuLink $item) {
menu_test_static_variable('insert');
}
@ -604,7 +606,7 @@ function menu_test_menu_link_insert($item) {
* @return
* A random string.
*/
function menu_test_menu_link_update($item) {
function menu_test_menu_link_update(MenuLink $item) {
menu_test_static_variable('update');
}
@ -614,7 +616,7 @@ function menu_test_menu_link_update($item) {
* @return
* A random string.
*/
function menu_test_menu_link_delete($item) {
function menu_test_menu_link_delete(MenuLink $item) {
menu_test_static_variable('delete');
}

View File

@ -9,6 +9,7 @@ use Drupal\user\Plugin\Core\Entity\User;
use Drupal\user\UserRole;
use Drupal\Core\Template\Attribute;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Drupal\menu_link\Plugin\Core\Entity\MenuLink;
/**
* @file
@ -1127,19 +1128,19 @@ function user_menu_site_status_alter(&$menu_site_status, $path) {
/**
* Implements hook_menu_link_presave().
*/
function user_menu_link_presave($link) {
function user_menu_link_presave(MenuLink $menu_link) {
// The path 'user' must be accessible for anonymous users, but only visible
// for authenticated users. Authenticated users should see "My account", but
// anonymous users should not see it at all. Therefore, invoke
// user_menu_link_load() to conditionally hide the link.
if ($link->link_path == 'user' && $link->module == 'system') {
$link->options['alter'] = TRUE;
if ($menu_link->link_path == 'user' && $menu_link->module == 'system') {
$menu_link->options['alter'] = TRUE;
}
// Force the Logout link to appear on the top-level of 'account' menu by
// default (i.e., unless it has been customized).
if ($link->link_path == 'user/logout' && $link->module == 'system' && empty($link->customized)) {
$link->plid = 0;
if ($menu_link->link_path == 'user/logout' && $menu_link->module == 'system' && empty($menu_link->customized)) {
$menu_link->plid = 0;
}
}