2

I would like users to be able to create band profiles (which will be a content type), and then those profiles will be associated with their user accounts via Entity Reference. However, I only want one profile per band, so I don't want each member of the band to be able to create a page for the band (but I'd like to have all members of the band be able to be related to the band page via Entity Reference).

So, before a user is able to create a band profile, I want them to search current bands on the site (either via Views or Search API, not sure which yet...probably whichever method allows me to solve the issue below). If the band does exist, then the user will select it and a reference will be created. However, if a profile for the band does not yet exist, I want the user to be presented with a link to the node add page to create a band.

This is where my question comes in. When a user creates a new band, how can I populate the node-add form with the terms that they searched for to begin with? So if a user searches for a band from "San Diego, CA" called "The Band", how can I populate the creation form with "San Diego, CA" and "The Band" without him having to enter the information again on his own?

2 Answers 2

1

I don't know of a module that solves exactly the problem you're describing out of the box, but you might be able to come close with Entity Reference View Widget and/or Node Reference URL Widget.

1
  • The view widget module definitely looks helpful and will probably be part of my solution. Thanks! Now to figure out the prepopulation part.
    – Mrweiner
    Oct 3, 2012 at 17:23
0

You can achieve using following hook_form_alter() steps:

1. In the hook_form_alter() function get the entities in which logged in user is referenced, this can be achieved by using the the view which i shown below. Get the query of the view and check whether logged in user is referenced in any band content type or not.

2. If any user is referenced in any node of Band content type then don't display node form and return directly

3. If user is not referenced then display content creation form of Band node type

In the following view i have kept field_referenced_users field which contains the referenced users in nodes. So change your field accordingly. Just import the below view and get the query, use this query in hook_form_alter() and check it. I have created view for article node type. You can change it accordingly.

$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Entities in Which Logged in User is Referenced';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'node';
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Contextual filter: Content: Referenced users (field_referenced_users) */
$handler->display->display_options['arguments']['field_referenced_users_target_id']['id'] = 'field_referenced_users_target_id';
$handler->display->display_options['arguments']['field_referenced_users_target_id']['table'] = 'field_data_field_referenced_users';
$handler->display->display_options['arguments']['field_referenced_users_target_id']['field'] = 'field_referenced_users_target_id';
$handler->display->display_options['arguments']['field_referenced_users_target_id']['default_action'] = 'default';
$handler->display->display_options['arguments']['field_referenced_users_target_id']['default_argument_type'] = 'current_user';
$handler->display->display_options['arguments']['field_referenced_users_target_id']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['field_referenced_users_target_id']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['field_referenced_users_target_id']['summary_options']['items_per_page'] = '25';
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'article' => 'article',
  'page' => 'page',
);
$handler->display->display_options['filters']['type']['group'] = 1;

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;

$handler->display->display_options['path'] = 'users-referenced-entity';
1
  • I think you misunderstood what I need done. Your solution seems to rely on the user already being referenced by a band entity. This is not the case. The issue is that the user is not currently related to the band he is searching for. He is searching to see if another user (another member of the band) has already created a profile for his band on the site. If he searches and his band appears in the results, then he selects it and the reference is created. If he does not see his band in the results, I want there to be a link to a band node add form, that is populated with his search query.
    – Mrweiner
    Oct 3, 2012 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.