Exemple #1
0
 public function build($form, &$form_state)
 {
     $form['type'] = array('#type' => 'select', '#title' => t('Type'), '#options' => array('wildcard' => t('Wildcard'), 'regex' => t('Regular Expression')), '#default_value' => 'wildcard');
     $form['path'] = array('#type' => 'textfield', '#title' => t('Path'), '#description' => t('Depending on the type selected, either a wildcard notation path or a regex statement.'), '#default_value' => '', '#required' => true);
     // Generate a list of menus.
     //		$menus = menu_get_menus();
     //		$menu_options = array();
     //		foreach ($menus as $machine_name => $name) {
     //			$menu_options[$name] = menu_tree_all_data($machine_name);
     //		}
     $form['mlid'] = array('#type' => 'select', '#title' => t('Menu Link'), '#description' => t('The menu link to associate the pattern with.'), '#options' => menu_parent_options(menu_get_menus(), array('mlid' => 0)), '#required' => true);
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => 'Save');
     $this->loadExisting($form, $form_state);
     return $form;
 }
/**
 * Add menu position rules for publication content type.
 */
function osha_add_menu_position_rules()
{
    if (module_exists('menu_position') && module_load_include('inc', 'menu_position', 'menu_position.admin')) {
        drupal_set_message('Create menu position rules ...');
        // Config menu_position contrib module.
        variable_set('menu_position_active_link_display', 'parent');
        $options = menu_parent_options(menu_get_menus(), array('mlid' => 0));
        $publications_menu = array_search('------ Publications', $options);
        $form_state = array('values' => array('admin_title' => 'Publications Menu Rule', 'plid' => $publications_menu !== NULL ? $publications_menu : 'main-menu:0', 'content_type' => array('publication' => 'publication'), 'op' => 'Save'));
        drupal_form_submit('menu_position_add_rule_form', $form_state);
        /* disabled temporarily for release branch
            $press_menu_entry = array_search('------ Press room', $options);
        
            $form_state = array(
              'values' => array(
                'admin_title' => 'Press room Menu Rule',
                'plid' => $press_menu_entry !== NULL ? $press_menu_entry : 'main-menu:0',
                'content_type' => array('press_release' => 'press_release'),
                'op' => 'Save',
              ),
            );
            */
        drupal_form_submit('menu_position_add_rule_form', $form_state);
        //menu position rule for Directive
        $directive_menu_entry = array_search('------ EU directives', $options);
        $form_state = array('values' => array('admin_title' => 'Directive Menu Rule', 'plid' => $directive_menu_entry !== NULL ? $directive_menu_entry : 'main-menu:0', 'pages' => 'legislation/directives/*' . PHP_EOL . 'legislation/directive/*', 'op' => 'Save'));
        drupal_form_submit('menu_position_add_rule_form', $form_state);
        //menu position rule for Guideline
        $guideline_menu_entry = array_search('------ EU guidelines', $options);
        $form_state = array('values' => array('admin_title' => 'Guideline Menu Rule', 'plid' => $guideline_menu_entry !== NULL ? $guideline_menu_entry : 'main-menu:0', 'pages' => 'legislation/guidelines/*', 'op' => 'Save'));
        drupal_form_submit('menu_position_add_rule_form', $form_state);
    }
}
 /**
  * Overrides Drupal\configuration\Config\Configuration::getAllIdentifiers().
  */
 public static function getAllIdentifiers($component)
 {
     global $menu_admin;
     // Need to set this to TRUE in order to get menu links that the
     // current user may not have access to (i.e. user/login)
     $menu_admin = TRUE;
     // This is intentionally to get always the same number of menus for each
     // user that can manage configurations.
     global $user;
     $current_user = $user;
     // Run the next line as administrator.
     $user = user_load(1);
     $menu_links = menu_parent_options(menu_get_menus(), array('mlid' => 0));
     // Back to the previous user.
     $user = $current_user;
     $options = array();
     foreach ($menu_links as $key => $name) {
         list($menu_name, $mlid) = explode(':', $key, 2);
         if ($mlid != 0) {
             $link = menu_link_load($mlid);
             $identifier = sha1(str_replace('-', '_', $link['menu_name']) . ':' . $link['link_path']);
             $options[$identifier] = "{$menu_name}: {$name}";
         }
     }
     $menu_admin = FALSE;
     return $options;
 }