I was examining the code for cck_signup_node_view_alter, and it looks to me like the code which unsets the link will never be reached.

Currently this function appears as follows:

      elseif (isset($links[$nodereference_url_link]) && cck_signup_event_is_past($node)) {
      	dpm($links,'links');
        // Check if event is in the past, remove link if that is the case.
        unset($links[$nodereference_url_link]);
      }

but the variable $links is never set previously in the method, rather $build['links']['nodereference_url'] is used.

Instead shouldn't this line of code be something along the lines of isset($build['links']['nodereference_url']['#links'][$nodereference_url])?

I also went to look at an older event & saw that the unset line was never reached...

Comments

zabelc’s picture

I reworked the whole if statement so it's a little bit clearer (at least to me) in breaking up the various conditions under which the link is removed or modified. I also noticed that capacity wasn't handled, so I added logic to remove the link if the capacity has been reached.

if( isset($build['links']['nodereference_url']['#links'][$nodereference_url_link]) ) {
	// If the nodereference url been set then we may need to remove or modify it
	if( cck_signup_event_is_past($node)) {
		// If event is in the past, remove link if that is the case.
		unset($build['links']['nodereference_url']['#links'][$nodereference_url_link]);
	} elseif( cck_signup_get_remaining_capacity($node) <= 0 ){
		// If event has met or exceeded capacity, remove link if that is the case.
		unset($build['links']['nodereference_url']['#links'][$nodereference_url_link]);
	} elseif( $signup = cck_signup_get_signup($node) ) {
		// If the user already has a signup, change link.
		$build['links']['nodereference_url']['#links'][$nodereference_url_link] = array(
			'href' => 'node/' . $signup->nid . '/edit',
			'title' => t('Manage your signup'),
			'attributes' => array('title' => t('Manage your signup')),
		);
	} else {
		//the user may signup
	}
}
jhedstrom’s picture

Status: Active » Needs review

Looks like you forgot to attach the patch :)

zabelc’s picture

@jhedstrom, sorry for the half-post. For some truly bizarre reason d.o was truncating my comment (likely at some unseen special character).

zabelc’s picture

I discovered a bug in the above: if there is no remaining capacity set (i.e. the field is there but empty) then the above interprets that as meaning that the event is closed. Thus the relevant line above should be replaced with:

} elseif( ($capacity = cck_signup_get_remaining_capacity($node)) && ($capacity<=0) ){

Giving the full patch:

if( isset($build['links']['nodereference_url']['#links'][$nodereference_url_link]) ) {
    // If the nodereference url been set then we may need to remove or modify it
    if( cck_signup_event_is_past($node)) {
        // If event is in the past, remove link if that is the case.
        unset($build['links']['nodereference_url']['#links'][$nodereference_url_link]);
    } elseif( ($capacity = cck_signup_get_remaining_capacity($node)) && ($capacity<=0) ){
        // If event has met or exceeded capacity, remove link if that is the case.
        unset($build['links']['nodereference_url']['#links'][$nodereference_url_link]);
    } elseif( $signup = cck_signup_get_signup($node) ) {
        // If the user already has a signup, change link.
        $build['links']['nodereference_url']['#links'][$nodereference_url_link] = array(
            'href' => 'node/' . $signup->nid . '/edit',
            'title' => t('Manage your signup'),
            'attributes' => array('title' => t('Manage your signup')),
        );
    } else {
        //the user may signup
    }
}