2

I created a view content about active classes and now I want to show them inside of user edit form to that they can see their clasess active with a contextual fiter url at view content, how can I make that? please help

1 Answer 1

2

You need to pass a contextual filter in the view of User ID, and pass the User ID from url as the value. It doesn't matter if this path is aliased, as it will look at the system path (user/uid) to get the value.

Then, the view will filter content based on relationship to that user id.

Without much more information, that is all I can give you to go on. But if it is a basic setup, that should work.

See: https://www.drupal.org/node/1578564

Then to show it on the form, it depends on what or where you want it.

One way would be to create a Block display of your View, and place it in a region on the block admin page. Be sure to set the visibility to authenticated roles, and the path to 'user/*/edit' so it only shows for users on the user edit form.

Another way, if you want to code it, would be embedding the output into the form with views_embed_view inside of a hook_form_alter for the user edit form. There are some examples on that doc page on how to use it.

Example:

$form['classes'] = [
  '#markup' => views_embed_view('your_view', 'block_display_id', $user_id);
]

Where $user_id is the user viewing the form.

4
  • $form['classes'] = [ '#markup' => views_embed_view('your_view', 'block_display_id', $user_id); ] Commented Sep 28, 2016 at 4:52
  • I did not understand that code, do I have to add it to form tpl.php file? Commented Sep 28, 2016 at 4:54
  • Before I tryed the first option but the app works with boostrap business theme and it didn't work, now I want to use you second option but i'm very confuse with the path of files that I have to modify Commented Sep 28, 2016 at 4:56
  • You would have to understand how to implement hook_form_alter in a custom module or template.php, and how to add a form element to a form to do so. You wouldn't edit form.tpl.php. The first option sounds more up your alley, though I can't/won't debug custom themes so I have no idea why bootstrap won't show the block.
    – Kevin
    Commented Sep 28, 2016 at 18:36

Your Answer

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

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