2

I have a block with dynamic content and two contextual links.

I have at the moment two problems:

  1. The second element is not visible.
  2. The first link does not allow to pass a date. I have to set a prefix e.g. "_"

How can I fix this problems?

Here is the main part of my module:

define('MY_DIR', 'somedir');

function mymodule_menu() {
    $items[MY_DIR] = array(
        'page callback' => 'status_page',
        'access callback' => TRUE,
        'type' => MENU_LOCAL_TASK,
    );
$items[MY_DIR.'/%'] = array(
    'page callback' => 'status_page',
    'access callback' => TRUE,
);
    $items[MY_DIR.'/edit'] = array(
        'title' => 'Edit item',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('mymodule_object_edit_form', 2),
        'access callback' => TRUE,
        'type' => MENU_LOCAL_TASK,
        'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
    );
    $items[MY_DIR.'/%date/update'] = array(
        'title' => 'Edit date',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('mymodule_object_edit_form', 2),
        'access callback' => TRUE,
        'type' => MENU_LOCAL_TASK,
        'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
    );

    return $items;
}

And here is my status page:

function status_page($date=null) {
    $object=new stdClass();
    $build=array();

    if(empty($date)) {
        $day=get_next_match();
    } else {
        // parse data
    }

    // set title
    $title="Title for ".$day->format("j.m.Y");
    drupal_set_title($title);

    $object->title = $title;
    $object->content = "Some dynamic content";

    $build[0] = array(
        '#theme' => 'filteredusers_object',
        '#object' => $object,
        '#contextual_links' => array(
            // contextual link 1
            'update-option' => array(
                MY_DIR,
                array("_$date"),
            ),
            // contextual link 2
            'edit.option' => array(
                MY_DIR.'/edit',
                array(),
            ),
        ),
    );
    return $build;
}

If something is unclear feel free to ask.

1 Answer 1

1

After one day of research I got a solution:

$build[1] = array(
    '#theme' => 'filteredusers_object',
    '#object' => $object,
    '#contextual_links' => array(array('', array())), // replaced by dummy data
    '#marker' => 'marker',
);

And adding this new hook:

function filteredusers_contextual_links_view_alter(&$element, &$items) {
    if(isset($element['#element']['#marker']) && 
             $element['#element']['#marker'] == "marker") {
        $element['#links']['custom-link'] = array(
            'title' => 'Some title',
            'href' => url('node/42', array('absolute' => TRUE)),
        );
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.