You are here

class EntityLegalMethodProfileForm in Entity Legal 7

Same name and namespace in other branches
  1. 7.2 methods/entity_legal.profile_form.inc \EntityLegalMethodProfileForm

Method class for displaying a checkbox on the user register form.

Hierarchy

Expanded class hierarchy of EntityLegalMethodProfileForm

File

methods/entity_legal.profile_form.inc, line 10
Method include file for 'form_link' and 'form_inline'.

View source
class EntityLegalMethodProfileForm extends EntityLegalMethod {

  /**
   * Get all legal document entities with profile form methods.
   *
   * @return array
   *   All documents that have profile form methods.
   */
  public function getProfileFormMethodDocuments() {
    $documents = $this
      ->getDocumentsForMethod('form_link', ENTITY_LEGAL_USER_ANONYMOUS);
    $documents += $this
      ->getDocumentsForMethod('form_inline', ENTITY_LEGAL_USER_ANONYMOUS);
    return $documents;
  }

  /**
   * Execution method for profile form method.
   *
   * @param array $form
   *   The user register form to affect.
   */
  public function execute(array &$form) {
    $documents = $this
      ->getProfileFormMethodDocuments();
    foreach ($documents as $document) {
      $field_name = 'legal_' . $document
        ->identifier();
      $form[$field_name] = array(
        '#type' => 'checkbox',
        '#title' => $document
          ->getAcceptanceLabel(),
        '#default_value' => $document
          ->userHasAgreed(),
        '#required' => TRUE,
      );
      switch ($document
        ->getAcceptanceDeliveryMethod(TRUE)) {
        case 'form_link':
          $document_uri = $document
            ->uri();
          $form[$field_name]['#description'] = t('Read the document at !url', array(
            '!url' => l(url($document_uri['path'], array(
              'absolute' => TRUE,
            )), $document_uri['path']),
          ));
          break;
        case 'form_inline':
          $document_render_array = entity_view(ENTITY_LEGAL_DOCUMENT_ENTITY_NAME, array(
            $document,
          ));
          $form[$field_name]['#prefix'] = render($document_render_array);
          break;
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityLegalMethod::getDocumentsForMethod public function Get all Entity Legal Documents for a given user type and method.
EntityLegalMethodProfileForm::execute public function Execution method for profile form method.
EntityLegalMethodProfileForm::getProfileFormMethodDocuments public function Get all legal document entities with profile form methods.