You are here

function drush_eck_entity_construction_kit in Entity Construction Kit (ECK) 7.2

Same name and namespace in other branches
  1. 7.3 includes/eck.drush.inc \drush_eck_entity_construction_kit()

Implements drush_hook_command().

Allows the user to select which entity, and bundle to show fields.

File

includes/eck.drush.inc, line 53
Drush support for ECK.

Code

function drush_eck_entity_construction_kit() {
  $entity_objs = EntityType::loadAll();
  if (empty($entity_objs)) {
    return drush_log('Entity Constuction Kit does not have any entities.', 'warning');
  }
  if (count($entity_objs) > 1) {
    $options = array();
    foreach ($entity_objs as $et) {
      $options[] = $et->label . ", " . $et->name;
    }
    $choice = drush_choice($options, dt("\nPick an entity type:\n"));
    if ($choice === FALSE) {
      return drush_log(dt('User cancelled'), 'ok');
    }
    $entity_type = $entity_objs[$choice];
  }
  else {
    $entity_type = $entity_objs[0];
    drush_log(dt('Only one entity type detected, proceeding with @entity_label, @entity_name, ', array(
      '@entity_label' => $entity_type->label,
      '@entity_name' => $entity_type->name,
    )), 'ok');
  }
  $bundle_objs = Bundle::loadByEntityType($entity_type);
  if (count($bundle_objs) > 1) {
    $options = array();
    foreach ($bundle_objs as $bundle) {
      $options[] = $bundle->label . ', ' . $bundle->name;
    }
    $choice = drush_choice($options, dt("\nPick a bundle:\n"));
    if ($choice === FALSE) {
      return drush_log(dt('User cancelled'), 'ok');
    }
    $bundle = $bundle_objs[$choice];
  }
  else {
    $bundle = $bundle_objs[0];
    drush_log(dt('Only one bundle detected, proceeding with @bundle_label, @bundle_name, ', array(
      '@bundle_label' => $bundle->label,
      '@bundle_name' => $bundle->name,
    )), 'ok');
  }
  $rows[] = array(
    '',
  );
  $rows[] = array(
    dt('Entity: '),
    $entity_type->label . ', ' . $entity_type->name,
  );
  $rows[] = array(
    '',
  );
  $rows = array_merge($rows, _eck_get_bundle($entity_type, $bundle));
  _eck_fix_underscores($rows);
  drush_print_table($rows, TRUE);
}