You are here

function eck__properties in Entity Construction Kit (ECK) 7.3

Properties page.

Parameters

string $entity_type_name: The name of an entity type.

Return value

array The page build.

1 string reference to 'eck__properties'
eck__bundle__menu in ./eck.bundle.inc
This function creates the menu items relevant to bundle administration.

File

./eck.properties.inc, line 16
Properties.

Code

function eck__properties($entity_type_name) {
  $current_path = current_path();
  $entity_type = EntityType::loadByName($entity_type_name);

  // Lets get the default properties.
  $default_properties = eck_get_default_properties();

  // Let get the actual properties of the entity type.
  $entity_type_properties = $entity_type->properties;

  // Lets arrenge the table with the appropiate action links.
  // This is the table where all properties are shown.
  $header = array(
    'machine_name' => t('Machine Name'),
    'name' => t('Name'),
    'type' => t('Type'),
    'behavior' => t('Behaviour'),
    'operations' => t('Operations'),
  );
  $options = array();

  // Lets process default properties first.
  foreach ($default_properties as $machine_name => $info) {
    $default_property_row = array();
    $info['machine_name'] = $machine_name;
    foreach ($header as $key => $label) {
      if ($key == 'name') {
        $key = "label";
      }
      if ($key != 'operations') {
        $default_property_row[] = array_key_exists($key, $info) ? $info[$key] : "";
      }
    }
    if (array_key_exists($machine_name, $entity_type_properties)) {
      $default_property_row[] = l(t('Deactivate'), $current_path . "/" . $machine_name . "/deactivate");
      unset($entity_type_properties[$machine_name]);
    }
    else {
      $link = "{$current_path}/{$machine_name}/activate";
      $default_property_row[] = l(t('Activate'), $link);
    }
    $options[] = $default_property_row;
  }

  // Ok, now lets do our custom properties.
  foreach ($entity_type_properties as $machine_name => $info) {
    $default_property_row = array();
    $info['machine_name'] = $machine_name;
    foreach ($header as $key => $label) {
      if ($key == 'name') {
        $key = "label";
      }
      if ($key != 'operations') {
        $default_property_row[] = array_key_exists($key, $info) ? $info[$key] : "";
      }
    }
    $operations = "";
    $ops = array(
      'edit' => "Edit",
      'delete' => "Delete",
      "behavior" => "behavior",
    );
    foreach ($ops as $op => $label) {
      if ($op == 'behavior' && !empty($info['behavior'])) {
        $label = "Edit " . $label;
      }
      elseif ($op == 'behavior' && empty($info['behavior'])) {
        $label = "Add " . $label;
      }
      $operations .= l($label, $current_path . "/" . $machine_name . "/{$op}") . "<br \\>";
    }
    $default_property_row[] = $operations;
    $options[] = $default_property_row;
  }
  $build['properties_table'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $options,
    '#empty' => t('No other properties for this entity type.'),
  );
  return $build;
}