You are here

public function EntityDefaultUIController::operationForm in Entity API 7

Builds the operation form.

For the export operation a serialized string of the entity is directly shown in the form (no submit function needed).

File

includes/entity.ui.inc, line 341
Provides a controller for building an entity overview form.

Class

EntityDefaultUIController
Default UI controller providing admin UI.

Code

public function operationForm($form, &$form_state, $entity, $op) {
  switch ($op) {
    case 'revert':
      $label = entity_label($this->entityType, $entity);
      $confirm_question = t('Are you sure you want to revert the %entity %label?', array(
        '%entity' => $this->entityInfo['label'],
        '%label' => $label,
      ));
      return confirm_form($form, $confirm_question, $this->path);
    case 'delete':
      $label = entity_label($this->entityType, $entity);
      $confirm_question = t('Are you sure you want to delete the %entity %label?', array(
        '%entity' => $this->entityInfo['label'],
        '%label' => $label,
      ));
      return confirm_form($form, $confirm_question, $this->path);
    case 'export':
      if (!empty($this->entityInfo['exportable'])) {
        $export = entity_export($this->entityType, $entity);
        $form['export'] = array(
          '#type' => 'textarea',
          '#title' => t('Export'),
          '#description' => t('For importing copy the content of the text area and paste it into the import page.'),
          '#rows' => 25,
          '#default_value' => $export,
        );
        return $form;
      }
    case 'import':
      $form['import'] = array(
        '#type' => 'textarea',
        '#title' => t('Import'),
        '#description' => t('Paste an exported %entity_type here.', array(
          '%entity_type' => $this->entityInfo['label'],
        )),
        '#rows' => 20,
      );
      $form['overwrite'] = array(
        '#title' => t('Overwrite'),
        '#type' => 'checkbox',
        '#description' => t('If checked, any existing %entity with the same identifier will be replaced by the import.', array(
          '%entity' => $this->entityInfo['label'],
        )),
        '#default_value' => FALSE,
      );
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Import'),
      );
      return $form;
  }
  drupal_not_found();
  exit;
}