function testMenuLinkTitle()
 {
     $plugin = new \menu_CrumbsMultiPlugin_link_title();
     $q = db_select('menu_links', 'ml');
     $q->fields('ml', array('mlid', 'link_path', 'menu_name'));
     $titles_by_path = array();
     foreach ($q->execute() as $row) {
         $link = menu_link_load($row->mlid);
         if ($link && !isset($links_by_path[$row->link_path][$row->menu_name])) {
             $titles_by_path[$row->link_path][$row->menu_name] = $link['title'];
         }
     }
     foreach ($titles_by_path as $path => $titles) {
         $router_item = crumbs_get_router_item($path);
         if ($router_item) {
             $plugin_result = $plugin->findTitle($path, $router_item);
             if (!is_array($plugin_result)) {
                 $this->fail("Plugin result for !path should not be empty.", array('!path' => $path));
                 continue;
             }
             ksort($plugin_result);
             ksort($titles);
             $this->assertEqual($titles, $plugin_result);
         }
     }
 }
 public function menuLink()
 {
     $mlid = $this->get('mlid');
     if (!$mlid) {
         return false;
     }
     return menu_link_load($mlid);
 }
Beispiel #3
0
 public function validate($form, &$form_state)
 {
     // Validate the MLID selection.
     $mlid_values = explode(':', $form_state['values']['mlid']);
     if (count($mlid_values) != 2 || menu_link_load($mlid_values[1]) === false) {
         form_set_error('mlid', t('The menu link provided is invalid.'));
         return;
     }
 }
Beispiel #4
0
 /**
  * Assert that at set of links is properly parented.
  */
 function assertMenuLinkParents($links, $expected_hierarchy)
 {
     foreach ($expected_hierarchy as $child => $parent) {
         $mlid = $links[$child]['mlid'];
         $plid = $parent ? $links[$parent]['mlid'] : 0;
         $menu_link = menu_link_load($mlid);
         menu_link_save($menu_link);
         $this->assertEqual($menu_link['plid'], $plid, format_string('Menu link %mlid has parent of %plid, expected %expected_plid.', array('%mlid' => $mlid, '%plid' => $menu_link['plid'], '%expected_plid' => $plid)));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getExistingObject(NodeInterface $node, Context $context)
 {
     $existing = null;
     if ($mlid = $this->findMenuItemId($node, $context)) {
         $existing = menu_link_load($mlid);
     }
     if (!$existing) {
         $context->logCritical(sprintf("%s: does not exists", $node->getPath()));
     }
     return array_intersect_key($existing, self::$defaults) + self::$defaults;
 }
Beispiel #6
0
 /**
  * Test creating, editing, deleting menu links via node form widget.
  */
 function testMenuNodeFormWidget()
 {
     // Disable the default main menu, so that no menus are enabled.
     $edit = array('menu_options[main]' => FALSE);
     $this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type'));
     // Verify that no menu settings are displayed and nodes can be created.
     $this->drupalGet('node/add/page');
     $this->assertText(t('Create Basic page'));
     $this->assertNoText(t('Menu settings'));
     $node_title = $this->randomName();
     $edit = array('title[0][value]' => $node_title, 'body[0][value]' => $this->randomString());
     $this->drupalPostForm(NULL, $edit, t('Save'));
     $node = $this->drupalGetNodeByTitle($node_title);
     $this->assertEqual($node->getTitle(), $edit['title[0][value]']);
     // Enable Tools menu as available menu.
     $edit = array('menu_options[main]' => 1, 'menu_options[tools]' => 1, 'menu_parent' => 'main:0');
     $this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type'));
     // Create a node.
     $node_title = $this->randomName();
     $edit = array('title[0][value]' => $node_title, 'body[0][value]' => $this->randomString());
     $this->drupalPostForm('node/add/page', $edit, t('Save'));
     $node = $this->drupalGetNodeByTitle($node_title);
     // Assert that there is no link for the node.
     $this->drupalGet('test-page');
     $this->assertNoLink($node_title);
     // Edit the node, enable the menu link setting, but skip the link title.
     $edit = array('menu[enabled]' => 1);
     $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
     // Assert that there is no link for the node.
     $this->drupalGet('test-page');
     $this->assertNoLink($node_title);
     // Edit the node and create a menu link.
     $edit = array('menu[enabled]' => 1, 'menu[link_title]' => $node_title, 'menu[weight]' => 17);
     $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
     // Assert that the link exists.
     $this->drupalGet('test-page');
     $this->assertLink($node_title);
     $this->drupalGet('node/' . $node->id() . '/edit');
     $this->assertOptionSelected('edit-menu-weight', 17, 'Menu weight correct in edit form');
     // Edit the node and remove the menu link.
     $edit = array('menu[enabled]' => FALSE);
     $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
     // Assert that there is no link for the node.
     $this->drupalGet('test-page');
     $this->assertNoLink($node_title);
     // Add a menu link to the Administration menu.
     $item = entity_create('menu_link', array('link_path' => 'node/' . $node->id(), 'link_title' => $this->randomName(16), 'menu_name' => 'admin'));
     $item->save();
     // Assert that disabled Administration menu is not shown on the
     // node/$nid/edit page.
     $this->drupalGet('node/' . $node->id() . '/edit');
     $this->assertText('Provide a menu link', 'Link in not allowed menu not shown in node edit form');
     // Assert that the link is still in the Administration menu after save.
     $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
     $link = menu_link_load($item['mlid']);
     $this->assertTrue($link, 'Link in not allowed menu still exists after saving node');
     // Move the menu link back to the Tools menu.
     $item['menu_name'] = 'tools';
     menu_link_save($item);
     // Create a second node.
     $child_node = $this->drupalCreateNode(array('type' => 'article'));
     // Assign a menu link to the second node, being a child of the first one.
     $child_item = entity_create('menu_link', array('link_path' => 'node/' . $child_node->id(), 'link_title' => $this->randomName(16), 'plid' => $item['mlid']));
     $child_item->save();
     // Edit the first node.
     $this->drupalGet('node/' . $node->id() . '/edit');
     // Assert that it is not possible to set the parent of the first node to itself or the second node.
     $this->assertNoOption('edit-menu-parent', 'tools:' . $item['mlid']);
     $this->assertNoOption('edit-menu-parent', 'tools:' . $child_item['mlid']);
     // Assert that unallowed Administration menu is not available in options.
     $this->assertNoOption('edit-menu-parent', 'admin:0');
 }
<?php

/**
 * @file
 * This template is used to print a single field in a view.
 *
 * It is not actually used in default Views, as this is registered as a theme
 * function which has better performance. For single overrides, the template is
 * perfectly okay.
 *
 * Variables available:
 * - $view: The view object
 * - $field: The field handler object that can process the input
 * - $row: The raw SQL result that can be used
 * - $output: The processed output that will normally be used.
 *
 * When fetching output from the $row, this construct should be used:
 * $data = $row->{$field->field_alias}
 *
 * The above will guarantee that you'll always get the correct data,
 * regardless of any changes in the aliasing that might happen if
 * the view is modified.
 */
global $base_url;
if (isset($row->_field_data['nid']['entity']->field_select_page_to_link['und'][0]['mlid'])) {
    $mlid = $row->_field_data['nid']['entity']->field_select_page_to_link['und'][0]['mlid'];
    $menu_link = menu_link_load($mlid);
    print "<a href='" . $base_url . '/' . $menu_link['link_path'] . "'>Read More</a>";
}
/**
 * @file
 * This template is used to print a single field in a view.
 *
 * It is not actually used in default Views, as this is registered as a theme
 * function which has better performance. For single overrides, the template is
 * perfectly okay.
 *
 * Variables available:
 * - $view: The view object
 * - $field: The field handler object that can process the input
 * - $row: The raw SQL result that can be used
 * - $output: The processed output that will normally be used.
 *
 * When fetching output from the $row, this construct should be used:
 * $data = $row->{$field->field_alias}
 *
 * The above will guarantee that you'll always get the correct data,
 * regardless of any changes in the aliasing that might happen if
 * the view is modified.
 */
global $base_url;
// print_r($row->_field_data['nid']['entity']);
if (isset($row->_field_data['nid']['entity']->field_other_link['und'][0]['url'])) {
    print "<a href='" . $base_url . '/' . $row->_field_data['nid']['entity']->field_other_link['und'][0]['url'] . "'>Read More</a>";
}
if (isset($row->_field_data['nid']['entity']->field_select_page_to_link['und'][0]['mlid'])) {
    $mlid = $row->_field_data['nid']['entity']->field_select_page_to_link['und'][0]['mlid'];
    $menuitem = menu_link_load($mlid);
    print "<a href='" . $base_url . '/' . $menuitem['link_path'] . "'>Read More</a>";
}
 /**
  * {@inheritdoc}
  */
 public function moveBefore($itemId, $otherItemId)
 {
     list(, , $parentId, $weight) = $this->validateMove($itemId, $otherItemId);
     $this->db->query("UPDATE {menu_links} SET weight = weight - 2 WHERE plid = :plid AND mlid <> :mlid AND weight <= :neww", [':mlid' => $otherItemId, ':plid' => $parentId, ':neww' => $weight]);
     $item = menu_link_load($itemId);
     $item['weight'] = $weight - 1;
     $item['plid'] = $parentId;
     if (!menu_link_save($item)) {
         throw new \RuntimeException("Could not save item");
     }
 }
Beispiel #10
0
/**
 * Helper function for showing the title and subtitle of a site section in the
 * highlighted region.
 *
 * The description is retrieved from the description of the menu item.
 */
function _bvng_get_title_data($node_count = NULL, $user = NULL, $req_path = NULL)
{
    $status = drupal_get_http_header("status");
    // This way disassociates the taxanavigation voc, is more reasonable, but a bit heavy.
    // Only 'GBIF Newsroom' has a shorter name in the nav.
    $source_menu = strpos($req_path, 'user') !== FALSE ? 'user-menu' : 'gbif-menu';
    $active_menu_item = menu_link_get_preferred(current_path(), $source_menu);
    if (strpos(current_path(), 'user') !== FALSE) {
        switch ($req_path) {
            case 'user/login':
                $title = array('name' => t('Login to GBIF'), 'description' => '');
                break;
            case 'user/register':
                $title = array('name' => t('Register New GBIF Account'), 'description' => t('Please, register to the GBIF data portal for downloading data, or login if you already have an account'));
                break;
            case 'user/password':
                $title = array('name' => t('Request a new password'), 'description' => t('Please enter your username or the registered email address in order to reset your password'));
                break;
            case 'node/241':
                $title = array('name' => t('Thanks for registering!'), 'description' => t('Please verify your email address'));
                break;
            default:
                if (isset($user->uid) && $user->uid !== 0) {
                    $user = user_load($user->uid);
                    $name = '';
                    $name .= _bvng_get_field_value('user', $user, 'field_firstname');
                    $name .= ' ';
                    $name .= _bvng_get_field_value('user', $user, 'field_lastname');
                    $title = array('name' => $name, 'description' => t('User account and personal settings'));
                } elseif ($status == '403 Forbidden') {
                    $title = array('name' => t('You need to log in to visit this page'), 'description' => t('403 Forbidden: proper permission required'));
                } elseif (isset($user->uid) && $user->uid == 0) {
                    $title = array('name' => t('Log in to GBIF'), 'description' => '');
                }
                break;
        }
    } elseif ($status == '404 Not Found') {
        $title = array('name' => t("Hmm, the page can't be found"), 'description' => t('404 Not Found'));
    } elseif ($status == '403 Forbidden') {
        $title = array('name' => t('You need to log in to visit this page'), 'description' => t('403 Forbidden: proper permission required'));
    } elseif ($active_menu_item) {
        // The resource/summary and resources/keyinformation are shared by two menu parents
        // so we force the title here.
        if (drupal_match_path($req_path, 'taxonomy/term/764') || drupal_match_path($req_path, 'node/234') || drupal_match_path($req_path, 'resources/archive')) {
            $title = array('name' => t('Resources'), 'description' => t('Tools and information to support the GBIF community'));
        } else {
            $parent = menu_link_load($active_menu_item['plid']);
            $title = array('mild' => $parent['mlid'], 'name' => $parent['link_title'] == 'GBIF News' ? 'GBIF Newsroom' : $parent['link_title'], 'description' => $parent['options']['attributes']['title']);
        }
    } elseif (strpos(current_path(), 'taxonomy/term') !== FALSE) {
        $term = taxonomy_term_load(arg(2));
        $title = array('name' => format_plural($node_count, 'Item tagged with "@term"', 'Items tagged with "@term"', array('@term' => $term->name)));
    } elseif (strpos(current_path(), 'search') !== FALSE) {
        $title = array('name' => t('Search GBIF'));
    }
    return $title;
}
Beispiel #11
0
 /**
  * Current Section MLID
  *
  * Returns the MLID of the current section (2nd level page).
  *
  * @param  string $preferred_menu The name of the menu to prefer.
  *
  * @return integer The section MLID.
  */
 public static function current_section_mlid($preferred_menu = 'main-menu')
 {
     $link = false;
     $found = array();
     // First, check to see if ablecore_menu is enabled and we have a match.
     if (module_exists('ablecore_menu')) {
         $link = ablecore_menu_get_preferred_link();
     }
     // Second, see if Drupal will give us one.
     if ($link === false) {
         $link = menu_link_get_preferred($_GET['q'], $preferred_menu);
     }
     if ($link !== false) {
         while ($link['plid'] !== "0") {
             if (in_array($link['plid'], $found)) {
                 break;
                 // Abort loop if a circular reference is detected
             } else {
                 $found[] = $link['plid'];
                 $link = menu_link_load($link['plid']);
             }
         }
         return $link['mlid'];
     } else {
         return false;
     }
 }
Beispiel #12
0
/**
 * Theme function to allow any menu tree to be themed as a Superfish menu.
 */
function magnetto_superfish($variables)
{
    global $user, $language;
    $id = $variables['id'];
    $menu_name = $variables['menu_name'];
    $mlid = $variables['mlid'];
    $sfsettings = $variables['sfsettings'];
    $menu = menu_tree_all_data($menu_name);
    if (function_exists('i18n_menu_localize_tree')) {
        $menu = i18n_menu_localize_tree($menu);
    }
    // For custom $menus and menus built all the way from the top-level we
    // don't need to "create" the specific sub-menu and we need to get the title
    // from the $menu_name since there is no "parent item" array.
    // Create the specific menu if we have a mlid.
    if (!empty($mlid)) {
        // Load the parent menu item.
        $item = menu_link_load($mlid);
        $title = check_plain($item['title']);
        $parent_depth = $item['depth'];
        // Narrow down the full menu to the specific sub-tree we need.
        for ($p = 1; $p < 10; $p++) {
            if ($sub_mlid = $item["p{$p}"]) {
                $subitem = menu_link_load($sub_mlid);
                $key = 50000 + $subitem['weight'] . ' ' . $subitem['title'] . ' ' . $subitem['mlid'];
                $menu = isset($menu[$key]['below']) ? $menu[$key]['below'] : $menu;
            }
        }
    } else {
        $result = db_query("SELECT title FROM {menu_custom} WHERE menu_name = :a", array(':a' => $menu_name))->fetchField();
        $title = check_plain($result);
    }
    $output['content'] = '';
    $output['subject'] = $title;
    if ($menu) {
        // Set the total menu depth counting from this parent if we need it.
        $depth = $sfsettings['depth'];
        $depth = $sfsettings['depth'] > 0 && isset($parent_depth) ? $parent_depth + $depth : $depth;
        $var = array('id' => $id, 'menu' => $menu, 'depth' => $depth, 'trail' => superfish_build_page_trail(menu_tree_page_data($menu_name)), 'sfsettings' => $sfsettings);
        if ($menu_tree = theme('superfish_build', $var)) {
            if ($menu_tree['content']) {
                // Add custom HTML codes around the main menu.
                if ($sfsettings['wrapmul'] && strpos($sfsettings['wrapmul'], ',') !== FALSE) {
                    $wmul = explode(',', $sfsettings['wrapmul']);
                    // In case you just wanted to add something after the element.
                    if (drupal_substr($sfsettings['wrapmul'], 0) == ',') {
                        array_unshift($wmul, '');
                    }
                } else {
                    $wmul = array();
                }
                $output['content'] = isset($wmul[0]) ? $wmul[0] : '';
                $output['content'] .= '<ul id="main-menu"';
                //'<ul id="superfish-' . $id . '"';
                $output['content'] .= ' class="menu sf-menu sf-' . $menu_name . ' sf-' . $sfsettings['type'] . ' sf-style-' . $sfsettings['style'];
                $output['content'] .= $sfsettings['itemcounter'] ? ' sf-total-items-' . $menu_tree['total_children'] : '';
                $output['content'] .= $sfsettings['itemcounter'] ? ' sf-parent-items-' . $menu_tree['parent_children'] : '';
                $output['content'] .= $sfsettings['itemcounter'] ? ' sf-single-items-' . $menu_tree['single_children'] : '';
                $output['content'] .= $sfsettings['ulclass'] ? ' ' . $sfsettings['ulclass'] : '';
                $output['content'] .= $language->direction == 1 ? ' rtl' : '';
                $output['content'] .= '">' . $menu_tree['content'] . '</ul>';
                $output['content'] .= isset($wmul[1]) ? $wmul[1] : '';
            }
        }
    }
    return $output;
}
 /**
  * Overrides Drupal\configuration\Config\Configuration::prepareBuild().
  */
 protected function prepareBuild()
 {
     $mlid = static::getMenuLinkByIdenfifier($this->getIdentifier(), TRUE);
     $this->data = menu_link_load($mlid);
     $this->data['parent_identifier'] = NULL;
     if (!empty($this->data['plid'])) {
         $parent = db_select('menu_links', 'ml')->fields('ml', array('menu_name', 'link_path', 'mlid'))->condition('mlid', $this->data['plid'])->execute()->fetchObject();
         if (!empty($parent)) {
             $this->data['parent_identifier'] = sha1(str_replace('-', '_', $parent->menu_name) . ':' . $parent->link_path);
         }
     }
     return $this;
 }
      <span class="sr-only">Next</span>
    </a>
</div>  
<?php 
    } elseif ($content["field_tipo_plantilla_html"]["#object"]->field_tipo_plantilla_html['und'][0]['value'] == '7') {
        ?>
  <div class="container-fluid l-btns">
    <div class="row">
      <?php 
        $nodes = array();
        foreach ($content["field_tipo_plantilla_html"]["#object"]->field_botones_linkeados as $key => $values) {
            foreach ($values as $key => $value) {
                $nodes[] = field_collection_item_load($value['value'], $reset = FALSE);
            }
            foreach ($nodes as $key => $value3) {
                $men = menu_link_load($value3->field_link_html['und'][0]['mlid']);
                ?>
          <div class="u-box col-lg-4 col-md-4 col-sm-6 col-xs-12">
            <div class="u-box-img">
              <img src="<?php 
                print_r(file_create_url($value3->field_imagen_linked['und'][0]['uri']));
                ?>
" alt="miller_lite_moments" />
            </div> 
            <?php 
                if (isset($value3->field_label_html['und'][0]['value'])) {
                    ?>
            
            <div class="u-box-text">
              <h3><?php 
                    print_r($value3->field_label_html['und'][0]['value']);