You are here

function flexiform_entity_remove_form in Flexiform 7

Form callback for removing entities.

1 string reference to 'flexiform_entity_remove_form'
FlexiformUIController::hook_menu in ./flexiform.admin.inc
Overrides hook_menu() defaults.

File

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

Code

function flexiform_entity_remove_form($form, &$form_state, $flexiform, $entity_namespace) {
  $form['#flexiform'] = $flexiform;
  $form['#entity_namespace'] = $entity_namespace;
  $manager = $flexiform
    ->getBuilder()
    ->getEntityManager();
  $dependants = $manager
    ->checkForDependants($entity_namespace);
  $settings = $manager
    ->getEntitySettings($entity_namespace);
  if ($entity_namespace == 'base_entity') {
    $form['message']['#markup'] = t('Cannot remove the base entity of a form.');
  }
  else {
    if (!empty($dependants)) {
      $dependantList = array(
        '#theme' => 'item_list',
        '#items' => $dependants,
      );
      $args = array(
        '%this' => $settings['label'],
        '!dependants' => drupal_render($dependantList),
      );
      $form['message']['#markup'] = t('Cannot remove %this as the following entities depend on it. Remove these entities first. !dependants', $args);
    }
    else {
      $form['message']['#markup'] = t('Are you sure you want to remove %this from the form?', array(
        '%this' => $settings['label'],
      ));
      $form['actions'] = array(
        '#type' => 'actions',
      );
      $form['actions']['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Remove'),
      );
    }
  }
  return $form;
}