Hello all, I have a code support request I was hoping you can help me with.

I have an EntityForm that Anonymous users can submit. This form has an Entity Reference to a custom ECK Entity that allows them to "Create a Person." So far, everything is working and "Add Person" link appears below, but the link is pointing to the admin path: admin/structure/entity-type/person/person/add

Since this is in the /admin/* section, it's themed using my Admin theme instead of the default site theme, so the Modal window has no styles since the Admin theme is not allowed to be seen by Anonymous users.

I've created a custom module that creates a new page (/create-person) which works and is themed correctly and allows users to create a person.

The problem I'm seeing is that I'm trying to use hook_references_dialog_entity_admin_paths() to tell References Dialog that the "Add Person" url should be "/create-person" but it's still pointing to the default admin path (admin/structure/entity-type/person/person/add).

Here's my code, could someone please tell me what I'm doing wrong? Please let me know if you need additional info:

<?php
/**
 * Implements hook_menu().
 */
function entityformtheme_menu(){
  $items['create-person'] = array(
    'page callback' => '_entityformtheme_my_eck_form_page',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
 * Gets the new entity page to work with ECK.
 */
function _entityformtheme_my_eck_form_page(){
   module_load_include('inc', 'eck', 'eck.entity');
   $bundle_name = 'person';
   return eck__entity__add('person', $bundle_name);
}

/**
 * Implements hook_references_dialog_entity_admin_paths().
 */
function entityformtheme_references_dialog_entity_admin_paths() {
  $admin_paths = array(
  /*
    If I use 'person' as the main array key here, I get these errors:

    Warning: strpos() expects parameter 1 to be string, array given in url_is_external() (line 2355 of ***/includes/common.inc).
    Warning: preg_match() expects parameter 2 to be string, array given in url_is_external() (line 2359 of ***/includes/common.inc).

   */
    'admin/structure/entity-type/person/person' => array(
      'add' => 'create-person',
      'edit' => 'person/person/[entity_id]/edit',
    ),
  );
  return $admin_paths;
}

Comments

msharkeyiii created an issue. See original summary.

msharkeyiii’s picture

Issue summary: View changes
msharkeyiii’s picture

Note to anyone reading this. Spent about 8 hours trying to figure it out, and ended up applying patch #3 from this ticket: https://www.drupal.org/node/2095029 which allows you to pass in your new arguments by reference.

My issue was exactly the same issue as here: https://www.drupal.org/node/1866846#comment-7922981

The hook_references_dialog_entity_admin_paths was turning [$op] into an array by adding in my new arguments rather than replacing them, and the references_dialog module was expecting a string. Basically hook_references_dialog_entity_admin_paths() is broken as it currently exists in the latest Dev version of resources_dialog.

Final custom module code looked like this:

<?php
/**
 * Implements hook_menu().
 */
function entityformtheme_menu(){
  $items['create-person'] = array(
    'page callback' => '_entityformtheme_my_eck_form_page',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
 * Gets the new entity page to work with ECK.
 */
function _entityformtheme_my_eck_form_page(){
   module_load_include('inc', 'eck', 'eck.entity');
   $bundle_name = 'person';
   return eck__entity__add('person', $bundle_name);
}

/**
 * Implements hook_references_dialog_entity_admin_paths_alter().
 *
 * This uses a custom hook in references_dialog created with patch #3 located here:
 * https://www.drupal.org/node/2095029
 */
function entityformtheme_references_dialog_entity_admin_paths_alter(&$admin_paths) {
  $admin_paths['person']['add'] = 'create-person';
  $admin_paths['person']['edit'] = 'person/person/[entity_id]/edit';
}
msharkeyiii’s picture

Changing this to an active bug report. Please close if redundant.