You are here

class FlexiformUIController in Flexiform 7

UI controller.

Hierarchy

Expanded class hierarchy of FlexiformUIController

1 string reference to 'FlexiformUIController'
flexiform_entity_info in ./flexiform.module
Implement hook_entity_info().

File

./flexiform.admin.inc, line 11
Model type editing UI.

View source
class FlexiformUIController extends EntityDefaultUIController {

  /**
   * Overrides operationCount();
   */
  protected function operationCount() {
    $count = 6;
    $count += !empty($this->entityInfo['i18n controller class']) ? 1 : 0;
    return $count;
  }

  /**
   * {@inheritdoc}
   */
  public function overviewForm($form, &$form_state, $conditions = array()) {
    $collapsed = TRUE;
    $tags = array();
    if (!empty($_GET['tags'])) {
      $tags = $conditions['tags'] = drupal_explode_tags($_GET['tags']);
      $collapsed = FALSE;
    }
    $form['filter'] = array(
      '#type' => 'fieldset',
      '#title' => t('Filter'),
      '#collapsible' => TRUE,
      '#collapsed' => $collapsed,
    );
    $form['filter']['#id'] = 'flexiform-filter-form';
    $form['filter']['tags'] = array(
      '#title' => t('Filter by tag'),
      '#type' => 'textfield',
      '#default_value' => drupal_implode_tags($tags),
      '#autocomplete_path' => 'admin/structure/flexiforms/autocomplete_tags',
    );
    $groups = flexiform_get_groups();
    if (count($groups) > 0) {
      $form['filter']['form_group'] = array(
        '#title' => t('Filter by group'),
        '#type' => 'select',
      );
      foreach ($groups as $group => $info) {
        $form['filter']['form_group']['#options'][$group] = $info['label'];
      }
    }
    $form['filter']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Filter'),
      '#name' => '',
    );

    // Overridden to allow the passing of conditions through.
    $form['table'] = $this
      ->overviewTable($conditions);
    $form['pager'] = array(
      '#theme' => 'pager',
    );
    $form['#method'] = 'get';
    $form['#submit'][] = 'flexiform_form_submit_rebuild';
    return $form;
  }

  /**
   * Overrides overviewTable();
   */
  public function overviewTable($conditions = array()) {
    $entities = entity_load($this->entityType, FALSE, $conditions);
    ksort($entities);
    $rows = array();
    foreach ($entities as $entity) {
      $rows[] = $this
        ->overviewTableRow($conditions, entity_id($this->entityType, $entity), $entity);
    }
    $render = array(
      '#theme' => 'table',
      '#header' => $this
        ->overviewTableHeaders($conditions, $rows),
      '#rows' => $rows,
      '#empty' => t('None.'),
    );
    return $render;
  }

  /**
   * Overrides overviewTableHeaders();
   */
  protected function overviewTableHeaders($conditions, $rows, $additional_header = array()) {
    $additional_header = array(
      t('Base Entity'),
      t('Bundle'),
    );
    return parent::overviewTableHeaders($conditions, $rows, $additional_header);
  }

  /**
   * Overrides overviewTableRow();
   */
  protected function overviewTableRow($conditions, $id, $entity, $additional_cols = array()) {
    $row = array();

    // Take the first column as usual.
    $row[] = array(
      'data' => array(
        '#theme' => 'flexiform_ui_overview_item',
        '#label' => entity_label($this->entityType, $entity),
        '#tags' => drupal_implode_tags($entity->tags),
        '#name' => !empty($this->entityInfo['exportable']) ? entity_id($this->entityType, $entity) : FALSE,
        '#url' => array(
          'path' => $this->path . '/manage/' . $id,
          'options' => array(),
        ),
        '#entity_type' => $this->entityType,
      ),
    );

    // Add the base entity.
    $base_info = entity_get_info($entity->base_entity);
    $row[] = $base_info['label'];
    $row[] = $base_info['bundles'][$entity->base_entity_bundle]['label'];

    // Add in any passed additional cols.
    foreach ($additional_cols as $col) {
      $row[] = $col;
    }
    $row[] = array(
      'data' => array(
        '#theme' => 'entity_status',
        '#status' => $entity->{$this->statusKey},
      ),
    );
    $i18n = !empty($this->entityInfo['i18n controller class']);

    // Add operations depending on the status.
    if (entity_has_status($this->entityType, $entity, ENTITY_FIXED)) {
      $row[] = array(
        'data' => l(t('clone'), $this->path . '/manage/' . $id . '/clone'),
        'colspan' => $this
          ->operationCount(),
      );
    }
    else {
      $row[] = l(t('edit'), $this->path . '/manage/' . $id);
      $base_path = $this->path . '/manage/' . $id . '/';
      $row[] = drupal_valid_path($base_path . 'form-fields') ? l(t('manage form fields'), $base_path . 'form-fields') : '';
      $row[] = drupal_valid_path($base_path . 'form-entities') ? l(t('manage form entities'), $base_path . 'form-entities') : '';
      if ($i18n) {
        $row[] = l(t('translate'), $this->path . '/manage/' . $id . '/translate');
      }
      $row[] = l(t('clone'), $this->path . '/manage/' . $id . '/clone');
      if (empty($this->entityInfo['exportable']) || !entity_has_status($this->entityType, $entity, ENTITY_IN_CODE)) {
        $row[] = l(t('delete'), $this->path . '/manage/' . $id . '/delete', array(
          'query' => drupal_get_destination(),
        ));
      }
      elseif (entity_has_status($this->entityType, $entity, ENTITY_OVERRIDDEN)) {
        $row[] = l(t('revert'), $this->path . '/manage/' . $id . '/revert', array(
          'query' => drupal_get_destination(),
        ));
      }
      else {
        $row[] = '';
      }
    }
    $row[] = l(t('export'), $this->path . '/manage/' . $id . '/export');
    return $row;
  }

  /**
   * {@inheritdoc}
   */
  public function hook_forms() {
    $forms = parent::hook_forms();
    $forms['flexiform_overview_form']['callback'] = 'flexiform_overview_form';
    return $forms;
  }

  /**
   * Overrides hook_menu() defaults.
   */
  public function hook_menu() {
    $wildcard = '%flexiform';
    $items = parent::hook_menu();
    $items[$this->path]['description'] = 'Manage flexiforms, including adding
		and removing fields and the display of fields.';

    // Change the way they clone things.
    $items["{$this->path}/manage/%entity_object/clone"]['page callback'] = 'flexiform_ui_get_clone_form';

    // Tags autocomplete pages.
    $items["{$this->path}/autocomplete_tags"] = array(
      'title' => 'Flexiform tags autocomplete',
      'page callback' => 'flexiform_autocomplete_tags',
      'page arguments' => array(
        4,
      ),
      'type' => MENU_CALLBACK,
      'file' => 'flexiform.admin.inc',
      'file path' => drupal_get_path('module', 'flexiform'),
      'access arguments' => array(
        'administer flexiforms',
      ),
    );
    $items["{$this->path}/manage/%entity_object/edit"]['context'] = MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE;
    $items["{$this->path}/manage/{$wildcard}/form-fields"] = array(
      'title' => 'Manage form fields',
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        'flexiform_manage_form_fields_form',
        4,
      ),
      'access callback' => 'flexiform_builder_admin_access',
      'access arguments' => array(
        4,
        'elements',
      ),
      'type' => MENU_LOCAL_TASK,
      'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
      'weight' => 2,
      'file' => 'flexiform.admin.inc',
      'file path' => drupal_get_path('module', 'flexiform'),
    );
    $items["{$this->path}/manage/{$wildcard}/form-fields/%flexiform_formfield"] = array(
      'title' => 'Edit Field',
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        'flexiform_field_configure_form',
        4,
        6,
      ),
      'file' => 'flexiform.admin.inc',
      'file path' => drupal_get_path('module', 'flexiform'),
      'access arguments' => array(
        'administer flexiforms',
      ),
    );
    $items["{$this->path}/manage/{$wildcard}/form-fields/%flexiform_formfield/edit"] = array(
      'title' => 'Configure',
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        'flexiform_field_configure_form',
        4,
        6,
      ),
      'file' => 'flexiform.admin.inc',
      'file path' => drupal_get_path('module', 'flexiform'),
      'type' => MENU_DEFAULT_LOCAL_TASK,
      'access arguments' => array(
        'administer flexiforms',
      ),
    );
    $items["{$this->path}/manage/{$wildcard}/form-fields/%flexiform_formfield/widget-type"] = array(
      'title' => 'Widget type',
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        'flexiform_field_widget_type_form',
        4,
        6,
      ),
      'access callback' => 'flexiform_field_widget_type_form_access',
      'access arguments' => array(
        4,
        6,
      ),
      'file' => 'flexiform.admin.inc',
      'file path' => drupal_get_path('module', 'flexiform'),
      'type' => MENU_LOCAL_TASK,
    );
    $items["{$this->path}/manage/{$wildcard}/form-fields/%flexiform_formfield/remove"] = array(
      'title' => 'Remove',
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        'flexiform_field_remove_form',
        4,
        6,
      ),
      'file' => 'flexiform.admin.inc',
      'file path' => drupal_get_path('module', 'flexiform'),
      'type' => MENU_LOCAL_TASK,
      'access arguments' => array(
        'administer flexiforms',
      ),
    );
    $items["{$this->path}/manage/{$wildcard}/form-entities"] = array(
      'title' => 'Manage form entities',
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        'flexiform_manage_form_entities_form',
        4,
      ),
      'access callback' => 'flexiform_builder_admin_access',
      'access arguments' => array(
        4,
        'entities',
      ),
      'type' => MENU_LOCAL_TASK,
      'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
      'weight' => 3,
      'file' => 'flexiform.admin.inc',
      'file path' => drupal_get_path('module', 'flexiform'),
    );
    $items["{$this->path}/manage/{$wildcard}/form-entities/%"] = array(
      'title' => 'Configure',
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        'flexiform_entity_configure_form',
        4,
        6,
      ),
      'type' => MENU_CALLBACK,
      'weight' => 3,
      'file' => 'flexiform.admin.inc',
      'file path' => drupal_get_path('module', 'flexiform'),
      'access arguments' => array(
        'administer flexiforms',
      ),
    );
    $items["{$this->path}/manage/{$wildcard}/form-entities/%/configure"] = array(
      'title' => 'Configure',
      'type' => MENU_DEFAULT_LOCAL_TASK,
      'weight' => 3,
    );
    $items["{$this->path}/manage/{$wildcard}/form-entities/%/remove"] = array(
      'title' => 'Remove',
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        'flexiform_entity_remove_form',
        4,
        6,
      ),
      'type' => MENU_LOCAL_TASK,
      'weight' => 4,
      'file' => 'flexiform.admin.inc',
      'file path' => drupal_get_path('module', 'flexiform'),
      'access arguments' => array(
        'administer flexiforms',
      ),
    );
    if (module_exists('rules_admin')) {
      $items["{$this->path}/manage/{$wildcard}/rules/add-action"] = array(
        'title' => 'Add Action',
        'page callback' => 'drupal_get_form',
        'page arguments' => array(
          'rules_admin_add_reaction_rule',
          "{$this->path}/manage/{$wildcard}/rules/add-action",
        ),
        'access callback' => TRUE,
        'file' => 'rules_admin.inc',
        'file path' => drupal_get_path('module', 'rules_admin'),
      );
    }

    // Generate paths for all other entity types with field UI.
    // @see field_ui_menu
    $entity_info = entity_get_info();
    foreach ($entity_info as $entity_type => $info) {

      // Only do this if the bundle is set.
      if (empty($info['bundles'])) {
        continue;
      }
      foreach ($info['bundles'] as $bundle_name => $bundle_info) {

        // Only act if there is an admin page set.
        if (empty($bundle_info['admin'])) {
          continue;
        }

        // Get the path for this bundle.
        $path = $bundle_info['admin']['path'];

        // The bundle arg could be either a position in the path or an actual
        // bundle.
        if (isset($bundle_info['admin']['bundle argument'])) {
          $bundle_arg = $bundle_info['admin']['bundle argument'];
        }
        else {
          $bundle_arg = $bundle_name;
        }

        // Extract access information, providing defaults.
        $access = array_intersect_key($bundle_info['admin'], drupal_map_assoc(array(
          'access callback',
          'access arguments',
        )));
        $access += array(
          'access callback' => 'user_access',
          'access arguments' => array(
            'administer site configuration',
          ),
        );
        $items["{$path}/forms"] = array(
          'title' => t('Manage Forms'),
          'type' => MENU_LOCAL_TASK,
          'page callback' => 'drupal_get_form',
          'page arguments' => array(
            'flexiform_overview_form',
            'flexiform',
            $entity_type,
            $bundle_arg,
          ),
          'description' => 'Manage ' . $info['label'] . ' Forms',
          'weight' => 3,
          'file' => 'includes/entity.ui.inc',
        ) + $access;
        $items["{$path}/forms/add"] = array(
          'title' => t('Add Form'),
          'type' => MENU_LOCAL_ACTION,
          'page callback' => 'flexiform_add_for_entity',
          'page arguments' => array(
            $entity_type,
            $bundle_arg,
          ),
          'description' => t('Add Form'),
          'file' => 'flexiform.admin.inc',
          'file path' => drupal_get_path('module', 'flexiform'),
        ) + $access;
      }
    }
    return $items;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityDefaultUIController::$entityInfo protected property
EntityDefaultUIController::$entityType protected property
EntityDefaultUIController::$id_count protected property
EntityDefaultUIController::$overviewPagerLimit public property Defines the number of entries to show per page in overview table.
EntityDefaultUIController::applyOperation public function Applies an operation to the given entity.
EntityDefaultUIController::entityFormSubmitBuildEntity public function Entity submit builder invoked via entity_ui_form_submit_build_entity().
EntityDefaultUIController::operationForm public function Builds the operation form.
EntityDefaultUIController::operationFormSubmit public function Operation form submit callback. 1
EntityDefaultUIController::operationFormValidate public function Operation form validation callback.
EntityDefaultUIController::overviewFormSubmit public function Overview form submit callback.
EntityDefaultUIController::overviewFormValidate public function Overview form validation callback.
EntityDefaultUIController::__construct public function
FlexiformUIController::hook_forms public function Provides definitions for implementing hook_forms(). Overrides EntityDefaultUIController::hook_forms
FlexiformUIController::hook_menu public function Overrides hook_menu() defaults. Overrides EntityDefaultUIController::hook_menu
FlexiformUIController::operationCount protected function Overrides operationCount(); Overrides EntityDefaultUIController::operationCount
FlexiformUIController::overviewForm public function Builds the entity overview form. Overrides EntityDefaultUIController::overviewForm
FlexiformUIController::overviewTable public function Overrides overviewTable(); Overrides EntityDefaultUIController::overviewTable
FlexiformUIController::overviewTableHeaders protected function Overrides overviewTableHeaders(); Overrides EntityDefaultUIController::overviewTableHeaders
FlexiformUIController::overviewTableRow protected function Overrides overviewTableRow(); Overrides EntityDefaultUIController::overviewTableRow