I would expect the registration link to change in a text stating that all slots are taken.
Now if the capacity has been reach, the registration link is still there on the node. When going to the register form, you see in the description of the slots field that there are 0 slots left.

Wouldn't it be better for the user to already mention it on the node? And when someone cancels, the link to register will reappear.
What are the options to do this? And wouldn't it be a feature to include in the core of this module? Maybe make it configurable in the settings if you want to take advantage of it or not?

Comments

phoenix’s picture

I've solved this by creating a new formatter. Based on the formatter that existed already, and some functions to check the capacity.
There will be a link if there's still capacity, if not the error "fully booked" will be shown.

For those interested:

/**
 * 
 * Implements hook_field_formatter_info
 */
function my_event_feature_field_formatter_info() {
  return array(
    'registration_link_full_text' => array(
      'label' => t('Registration Link - capacity full text'),
      'field types' => array('registration'),
      'settings' => array(
        'label' => ' ',
      ),
    ),
  );
}

/**
 * Implements hook_field_formatter_settings_form().
 */
function my_event_feature_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];

  $element = array();

  if ($display['type'] == 'registration_link_full_text') {
    $element['label'] = array(
      '#title' => t('Label'),
      '#type' => 'textfield',
      '#size' => 20,
      '#default_value' => $settings['label'],
      '#required' => FALSE,
      '#description' => t("Optional label to use when displaying the registration title or link. Leave blank to use the parent event's label."),
    );
  }

  return $element;
}

/**
 * Implements hook_field_formatter_settings_summary().
 */
function my_event_feature_field_formatter_settings_summary($field, $instance, $view_mode) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];

  $summary = '';

  if ($display['type'] == 'registration_link_full_text') {
    if (!empty($settings['label'])) {
      $summary = t('Registration label: @label.', array('@label' => $settings['label']));
    }
    else {
      $summary = t('Registration label: Parent label.');
    }
  }

  return $summary;
}

/**
 * 
 * Implements hook_field_formatter_view
 * 
 */
function my_event_feature_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  
  // we know we should only have a single item
  if (isset($items[0]['registration_type']) && !empty($items[0]['registration_type'])) {
    $reg_type = registration_type_load($items[0]['registration_type']);
    $settings = $display['settings'];
    $label = !empty($settings['label']) ? $settings['label'] : $reg_type->label;

    switch ($display['type']) {
      case 'registration_link_full_text':
        // Enable registration link if accessible.
        if (registration_register_page_access($entity_type, $entity)) {
          list($entity_id) = entity_extract_ids($entity_type, $entity);
            if (registration_status($entity_type, $entity_id)) {
            $uri = entity_uri($entity_type, $entity);
            $element[0] = array(
              '#markup' => theme('registration_link',
                array(
                  'label' => $label,
                  'path' => $uri['path'] . '/register'
                )
              )
            );
          }
          else {
            $error_message = t('Fully booked');
            $element[0] = array(
              '#markup' => check_plain($error_message),
            );
          }
        }
        break;
    }
  }

  return $element;
}
phoenix’s picture

Title: REmove register link when capacity is full » Remove register link when capacity is full
Issue summary: View changes
aucovic’s picture

I modified slightly the formatter above and instead the registration link, I included the registration form. Also implemeted hook_form_alter to tweak the form. (If you only need to tweak the form you can use that hook as a standalone in your custom module). Cheers!

Custom module source:

/**
*
* Implements hook_field_formatter_info
*/
function entity_registration_custom_field_formatter_info() {
  return array(
    'registration_form_custom' => array(
      'label' => t('Registration Link - capacity full text'),
      'field types' => array('registration'),
      'settings' => array(
        'label' => ' ',
      ),
    ),
  );
}
/**
* Implements hook_field_formatter_settings_form().
*/
function entity_registration_custom_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
  $element = array();
  if ($display['type'] == 'registration_form_custom') {
    $element['label'] = array(
      '#title' => t('Label'),
      '#type' => 'textfield',
      '#size' => 20,
      '#default_value' => $settings['label'],
      '#required' => FALSE,
      '#description' => t("Optional label to use when displaying the registration title or link. Leave blank to use the parent event's label."),
    );
  }
  return $element;
}
/**
* Implements hook_field_formatter_settings_summary().
*/
function entity_registration_custom_field_formatter_settings_summary($field, $instance, $view_mode) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
  $summary = '';
  if ($display['type'] == 'registration_form_custom') {
    if (!empty($settings['label'])) {
      $summary = t('Registration label: @label.', array('@label' => $settings['label']));
    }
    else {
      $summary = t('Registration label: Parent label.');
    }
  }
  return $summary;
}
/**
*
* Implements hook_field_formatter_view
*
*/
function entity_registration_custom_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  // we know we should only have a single item
  if (isset($items[0]['registration_type']) && !empty($items[0]['registration_type'])) {
    $reg_type = registration_type_load($items[0]['registration_type']);
    $settings = $display['settings'];
    $label = !empty($settings['label']) ? $settings['label'] : $reg_type->label;
    switch ($display['type']) {
      case 'registration_form_custom':
        // Enable registration link if accessible.
        if (registration_register_page_access($entity_type, $entity)) {
          list($entity_id) = entity_extract_ids($entity_type, $entity);
            if (registration_status($entity_type, $entity_id)) {
				$registration = entity_get_controller('registration')->create(array(
				  'entity_type' => $entity_type,
				  'entity_id' => $entity_id,
				  'type' => $reg_type->name,
				));
				$element[0] = drupal_get_form('registration_form', $registration);
          }
          else {
            $error_message = t('Registration is closed - tickets are sold out.');
            $element[0] = array(
              '#markup' => check_plain($error_message),
            );
          }
        }
        break;
    }
  }
  return $element;
}



/**
*
* Implements hook_form_alter
*
*/
function entity_registration_custom_form_alter(&$form, &$form_state, $form_id) {
	global $user;
	if ($form_id == 'registration_form') {
		if (!in_array('administrator', array_values($user->roles))) {
			unset($form['who_message']); // Removes 'Who Is registering msg' markup for all users except admin
		}  
		$form['count']['#title'] = 'RVSP quantity'; // Set spaces (slots) label
		$form['actions']['submit']['#value'] = 'Register now'; // Change submit button text
		
		$node = node_load(arg(1));
		if($node->type == 'event') {
			$form['registration_description'] = array(
			  '#type' => 'markup',
			  '#markup' => "<p>Please use the form below to register via PayPal</p>",
			  "#weight" => -10
			);
		}
	}
}

ptmkenny’s picture

It would be great to have this as a patch to the module. If the event is full and the wait list feature is not enabled, it does not make any sense to show the registration form.

timwhelan’s picture

First, Thanks for sharing this content. I would love to see this as a patch. Not as familiar with creating custom modules just yet.

EDIT: So not know what to do I added this to a test site and could not get the capacity reached to turn off registration. to the bottom of the registartion.field.inc file, just to test it out.

Any other suggestions for testing. Would I need to create a new module and place that into the modules folder within the Registration module folder?
Thanks!!!

Hitby’s picture

StatusFileSize
new2.97 KB

Attached the code above zipped in a custom module with info file. Just stick it in your sites/all/modules directory and activate it in your module interface.

gandhiano’s picture

Version: 7.x-1.2 » 7.x-1.x-dev

I don't know if this should be a submodule of Entity Registration, or simply be integrated in the main module itself (it's UI polishing, even kind of basic functioning).

It would also be important to know how it interoperates with the waitlist submodule. When this is active, I would expect to see the user getting a link to put himself in the waiting list, rather than just removing it completely.

Hitby’s picture

Hi Gandhiano,
If the wait list is full the registration form is removed (I'm having to manually place a block explaining this when it happens on a daily basis. If someone cancels and a place on the waitlist is free then the form re-appears.

gandhiano’s picture

Version: 7.x-1.x-dev » 7.x-1.3
Status: Active » Needs review

Thanks Hitby for clarifying, in the meanwhile I think the behavior asked for in the title is actually standard in the current version. At least for me, without relying on your file, the link to register just disappears (nothing in substitution though, but this can be easily overcome with setting up a no results page for a view)

rattusrattus’s picture

StatusFileSize
new2.28 KB

Here's a patch to include some of the functionality provided in #1 plus a field configuration setting so that users can choose whether the link should be displayed.

I think there's some confusion between registration which are disabled and registrations which are enabled but registration is not possible for some reason, i.e. not enough capacity, the registration time period has not begun, etc. The current dev release of the module will not show a registration link in the case of the former but there is no present check to validate the latter. The attached patch allows users to decided whether to include the second validation check when rendering the registration link.

With regards to substitution, rather than simply removing the link, this is made more complicated by there being a number of reasons why registration isn't possible. registration_status() will return the exact reason but I expect they're going to be a bit lengthy in most cases.

tanc’s picture

Version: 7.x-1.3 » 7.x-1.x-dev
StatusFileSize
new2.19 KB

Attached a re-roll against 7.x-1.x-dev

john.oltman’s picture

Version: 7.x-1.x-dev » 3.3.x-dev
Status: Needs review » Active
john.oltman’s picture

Status: Active » Closed (duplicate)
Related issues: +#3499231: Show causes with registration link and form