You are here

public function FlexiformElementUserRoles::form in Flexiform 7

Return the form element for this FlexiformElement.

Overrides FlexiformElement::form

File

includes/element/user_roles.element.inc, line 15
Contains class for the User roles element.

Class

FlexiformElementUserRoles
Class to add the node title field to a form.

Code

public function form($form, &$form_state, $entity, $language = LANGUAGE_NONE) {
  $parents = $form['#parents'];
  $parents[] = 'roles';

  // Work out the default value.
  $default = '';
  if (!empty($this->settings['default_value']['default_value'])) {
    $default = $this->settings['default_value']['default_value'];
  }
  if (!empty($this->settings['default_value']['use_tokens'])) {
    $default = $this
      ->replaceCtoolsSubstitutions($default, $form['#flexiform_entities']);
  }
  $roles = array_map('check_plain', user_roles(TRUE));
  $form[$this->element_namespace] = array(
    '#type' => 'checkboxes',
    '#parents' => $parents,
    '#title' => $this
      ->label(),
    '#required' => FALSE,
    '#default_value' => !empty($entity->roles) ? array_keys($entity->roles) : array(),
    '#options' => $roles,
  );
  $form = parent::form($form, $form_state, $entity);
  return $form;
}