Think about Drupal Developer following menu construction:
- Web page 1 kind: article
- Web page 2 comes from a view
- Web page 3 kind: fascinating < need this
- Web page 4 kind: random
- Web page 5 kind: random
- Web page 4 kind: random
- Web page 3 kind: fascinating < need this
- Web page 6 kind: article
Let’s imagine I am on Web page 5. I need to know if any mother or father menu merchandise’s node has Drupal Developer content material kind fascinating.
I acquired a menu merchandise id menu_link_content:uuid for Web page 5. My present strategy is Drupal Developer following:
<?php $values['menu_parent'] = 'essential:menu_link_content:uuid'; listing($menuName, $entityName, $uuid) = explode(':', $values['menu_parent'], 3); $menuLinkManager = Drupal::service('plugin.supervisor.menu.hyperlink'); $mother and father = $menuLinkManager->getParentIds($entityName . ':' . $uuid); foreach ($mother and father as $parentPluginId) { $mlc_ids = Drupal::database() ->choose('menu_tree', 'mt') ->fields('mt', ['route_param_key']) ->situation('route_name', 'entity.node.canonical') ->situation('id', $parentPluginId) ->execute() ->fetchCol(); // menu_tree offers again node=nid if ($mlc_id && strpos($mlc_id, 'node=') !== false) { // cut up node=nid into separate values listing($entityString, $nid) = explode("=", $mlc_id, 2); // load Drupal Developer respective node and see if it's a mission $parentNode = Drupal::entityManager()->getStorage('node')->load($nid); if ($parentNode) { $parentType = $parentNode->getType(); // we discovered Drupal Developer mother or father mission node if ('mission' == $parentType) { $node->set('field_project_ref', $nid); $node->save(); drupal_set_message( t("Drupal Development Company content material was mechanically added a mission reference as a result of it is mother or father menu objects."), 'standing' ); break; } } } }
So I’d go on and cargo Drupal Developer node if Drupal Developer database assertion discovered one thing and verify Drupal Developer node kind and many others. I simply marvel if there was a extra performant/ higher, out of Drupal Developer field method of doing that?
One thing like
$menuLinkContent->getTargetEntity()->getType()
or
entityManager()->loadEntityFromMenu()
could be good.