setContext() public méthode

Set the contexts that this menu item is available for
public setContext ( array $contexts ) : void
$contexts array An array of context strings. Use 'all' to match all contexts.
Résultat void
 /**
  * ElggMenuItem factory method
  *
  * This static method creates an ElggMenuItem from an associative array.
  * Required keys are name, text, and href.
  *
  * @param array $options Option array of key value pairs
  *
  * @return ElggMenuItem or null on error
  */
 public static function factory($options)
 {
     if (!isset($options['name']) || !isset($options['text'])) {
         return null;
     }
     if (!isset($options['href'])) {
         $options['href'] = '';
     }
     $item = new ElggMenuItem($options['name'], $options['text'], $options['href']);
     unset($options['name']);
     unset($options['text']);
     unset($options['href']);
     // special catch in case someone uses context rather than contexts
     if (isset($options['context'])) {
         $options['contexts'] = $options['context'];
         unset($options['context']);
     }
     // make sure contexts is set correctly
     if (isset($options['contexts'])) {
         $item->setContext($options['contexts']);
         unset($options['contexts']);
     }
     if (isset($options['link_class'])) {
         $item->setLinkClass($options['link_class']);
         unset($options['link_class']);
     } elseif (isset($options['class'])) {
         elgg_deprecated_notice("ElggMenuItem::factory() does not accept 'class' key anymore, use 'link_class' instead", 1.9);
         $item->setLinkClass($options['class']);
         unset($options['class']);
     }
     if (isset($options['item_class'])) {
         $item->setItemClass($options['item_class']);
         unset($options['item_class']);
     }
     if (isset($options['data']) && is_array($options['data'])) {
         $item->setData($options['data']);
         unset($options['data']);
     }
     foreach ($options as $key => $value) {
         if (isset($item->data[$key])) {
             $item->data[$key] = $value;
         } else {
             $item->{$key} = $value;
         }
     }
     return $item;
 }
Exemple #2
0
 /**
  * ElggMenuItem factory method
  *
  * This static method creates an ElggMenuItem from an associative array.
  * Required keys are name, text, and href.
  *
  * @param array $options Option array of key value pairs
  *
  * @return ElggMenuItem or NULL on error
  */
 public static function factory($options)
 {
     if (!isset($options['name']) || !isset($options['text'])) {
         return NULL;
     }
     if (!isset($options['href'])) {
         $options['href'] = '';
     }
     $item = new ElggMenuItem($options['name'], $options['text'], $options['href']);
     unset($options['name']);
     unset($options['text']);
     unset($options['href']);
     // special catch in case someone uses context rather than contexts
     if (isset($options['context'])) {
         $options['contexts'] = $options['context'];
         unset($options['context']);
     }
     // make sure contexts is set correctly
     if (isset($options['contexts'])) {
         $item->setContext($options['contexts']);
         unset($options['contexts']);
     }
     if (isset($options['link_class'])) {
         $item->setLinkClass($options['link_class']);
         unset($options['link_class']);
     }
     if (isset($options['item_class'])) {
         $item->setItemClass($options['item_class']);
         unset($options['item_class']);
     }
     if (isset($options['data']) && is_array($options['data'])) {
         $item->setData($options['data']);
         unset($options['data']);
     }
     foreach ($options as $key => $value) {
         if (isset($item->data[$key])) {
             $item->data[$key] = $value;
         } else {
             $item->{$key} = $value;
         }
     }
     return $item;
 }
 public function testInContextWithParticularContext()
 {
     $item = new \ElggMenuItem('name', 'text', 'url');
     $item->setContext(array('blog', 'bookmarks'));
     $this->assertTrue($item->inContext('blog'));
     $this->assertFalse($item->inContext('file'));
 }
Exemple #4
0
    elgg_register_menu_item('page', array('name' => elgg_echo("faq:ask"), 'text' => elgg_echo("faq:ask"), 'href' => elgg_get_site_url() . "faq/ask", 'section' => 'b', 'context' => 'faq'));
}
if (elgg_is_admin_logged_in()) {
    elgg_register_menu_item('page', array('name' => elgg_echo("faq:add"), 'text' => elgg_echo("faq:add"), 'href' => elgg_get_site_url() . "faq/add", 'section' => 'c', 'context' => 'faq'));
    elgg_register_menu_item('page', array('name' => elgg_echo("faq:asked", array(getUserQuestionsCount())), 'text' => elgg_echo("faq:asked", array(getUserQuestionsCount())), 'href' => elgg_get_site_url() . "faq/asked", 'section' => 'c', 'context' => 'faq'));
}
?>

<div class="elgg-module elgg-module-aside">
	<div class="elgg-head">
		<h3><?php 
echo elgg_echo('faq:sidebar:categories');
?>
</h3>
	</div>
	<div>
		<?php 
$cats = getCategories();
$category_links = '';
foreach ($cats as $id => $cat) {
    $url = "faq/list?categoryId=" . $id;
    $item = new ElggMenuItem($cat, $cat, $url);
    $item->setContext('faq');
    $item->setSection('d');
    $category_links .= elgg_view('navigation/menu/elements/item', array('item' => $item));
}
echo $category_links;
?>
	</div>
</div>
Exemple #5
0
<div class="elgg-module elgg-module-aside">
	<div class="elgg-head">
		<h3><?php 
echo elgg_echo('celebrations:list_monthly');
?>
</h3>
	</div>
	<div>
		<?php 
$filterid = $vars['filterid'];
for ($i = 1; $i <= 12; $i += 1) {
    $url = elgg_get_site_url() . "celebrations/celebrations/{$i}/{$filterid}";
    $item = new ElggMenuItem("celebrations_month_{$i}", elgg_echo("celebrations:month:{$i}"), $url);
    $item->setContext('celebrations');
    $item->setSection('a');
    $celebrations_monthly .= elgg_view('navigation/menu/elements/item', array('item' => $item));
}
echo "<ul>" . $celebrations_monthly . "</ul>";
?>
	</div>
</div>