You are here

function registration_field_formatter_view in Entity Registration 8.2

Same name and namespace in other branches
  1. 7.2 includes/registration.field.inc \registration_field_formatter_view()
  2. 7 includes/registration.field.inc \registration_field_formatter_view()

Implements hook_field_formatter_view().

File

includes/registration.field.inc, line 262
Field hooks.

Code

function registration_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']) ? _registration_translate($settings['i18n_string_key'] . ':label', $settings['label']) : $reg_type->label;
    list($entity_id) = entity_extract_ids($entity_type, $entity);
    switch ($display['type']) {
      case 'registration_link':

        // Enable registration link if accessible.
        if (registration_register_page_access($entity_type, $entity) && registration_status($entity_type, $entity_id)) {
          $uri = entity_uri($entity_type, $entity);

          // @FIXME
          // theme() has been renamed to _theme() and should NEVER be called directly.
          // Calling _theme() directly can alter the expected output and potentially
          // introduce security issues (see https://www.drupal.org/node/2195739). You
          // should use renderable arrays instead.
          //
          //
          // @see https://www.drupal.org/node/2195739
          // $element[0] = array(
          //             '#markup' => theme('registration_link',
          //               array(
          //                 'label' => $label,
          //                 'path' => $uri['path'] . '/register',
          //                 'registration type' => $reg_type,
          //                 'entity_type' => $entity_type,
          //                 'entity' => $entity,
          //               )
          //             ),
          //           );
        }
        break;
      case 'registration_form':

        // Enable registration form if accessible.
        if (registration_register_page_access($entity_type, $entity) && 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::formBuilder()
            ->getForm('registration_form', $registration);
        }
        break;
      case 'registration_type':
        $element[0] = array(
          '#markup' => $label,
        );
        break;
    }
  }
  return $element;
}