You are here

function references_dialog_get_admin_path in References dialog 7

Get the admin path (edit/add) page for a particular entity.

Parameters

string $entity_type the entity type:

string $op Which operation to perform. Either "edit" or "add".:

string $bundle The bundle to use.:

mixed $entity The entity to edit. This is only used with the "edit" operation.:

Return value

string The path where the entity can be edited or created.

2 calls to references_dialog_get_admin_path()
references_dialog_entityreference_edit_link in ./references_dialog.dialog_widgets.inc
Edit link callback for entity references.
references_dialog_entityreference_link_helper in ./references_dialog.dialog_widgets.inc

File

./references_dialog.module, line 786
This the main module file.

Code

function references_dialog_get_admin_path($entity_type, $op, $bundle = NULL, $entity = NULL) {

  // Let's cache the paths.
  $paths =& drupal_static(__FUNCTION__, NULL);
  if (!isset($paths)) {
    $paths = module_invoke_all('references_dialog_entity_admin_paths');
  }
  if (isset($paths[$entity_type]) && isset($paths[$entity_type][$op])) {
    $path = $paths[$entity_type][$op];

    // Create a wrapper, so we can deal with this in a sane way.
    $wrapper = entity_metadata_wrapper($entity_type, $entity);

    // Replace [entity_id] with the entity id.
    if (isset($entity)) {
      $path = str_replace('[entity_id]', $wrapper
        ->getIdentifier(), $path);
    }
    if (!$bundle) {
      $bundle = $wrapper
        ->getBundle();
    }
    if ($bundle) {
      $path = str_replace('[bundle]', $bundle, $path);

      // Some entities (like node) provide a sort of sanitized version.
      // This makes sure we support this.
      $bundle = strtr($bundle, array(
        '_' => '-',
      ));
      $path = str_replace('[bundle-sanitized]', $bundle, $path);
    }
    return $path;
  }
  return FALSE;
}