2

In a node edit form i want to display an editable view, so an author can not only edit the node itself but also can alter some values of other nodes represented by the view, which is editable via the editable views module. How can i alter the node edit form in order to display that view?

  • Which approach did you ultimately use, the contrib module or a custom solution? – Kimberly W Dec 28 '18 at 17:30
  • I wrote a custom module because of it's light weight. – Madam Adam Dec 28 '18 at 18:10
3

The EmbeddedViewField module is able to render a view, regardless of whether the user is editing or displaying the entity (node) that has the EmbeddedViewField. Here is a quote about that module (from its project page):

... will allow you to render a view as any other field.

It is based on keithm's ViewField module, except that it will always render the view, regardless of whether the user is editing or displaying the entity that has the EmbeddedViewField. The view used for displaying is controlled by the default value set for the view.

This is useful in situations where you don't want end users to control the content being displayed by the view, but you still want a flexible way to insert content (views with text, images, media etc.) along with the rest of the fields in the form.

Context, Panels and Blocks could be used to place views and edit forms in the same page, but not to embed views between specific fields.

  • 1
    Welcome! Please verify my edited version of your answer. And be aware that you should always avoid to just post a "link" to some module (always add some details about it, eg like I did). That prevents it'll be considered as a link-only answer (and get deleted by moderators). OK? – Pierre.Vriens Aug 7 '15 at 14:09
1

I solved the problem showing the view in the node edit form only by writing a tiny module containing this code:

<?php

/*
 * Implementation of hook_form_alter()
 */

function mymodulname_form_alter(&$form, &$form_state, $form_id){
     // target a single form only
  if($form_id == "mynodeform_node_form"){
      $form['html_markup'] = array(
        '#markup' =>views_embed_view('machinenameofmyview','default'),
        '#weight' => 1
        );    
  }
}
1

There are a few ways you can do this - if you are using Drupal 7 - take a look at this module: https://drupal.org/project/token_embed_views Another less desireable way would be to use your PHP filter and the views_embed_view function https://api.drupal.org/api/views/views.module/function/views_embed_view/7

If you are looking to actually load this view in the edit side, you could possibly do a "hook_form_alter" to allow you to put your own content in the form...

  • My problem is not displaying a view, but displaying a view in node edit form only. Displaying a view is pretty easy with display suite and views content panes, but it's not possible to show this pane in edit form only. – Madam Adam Apr 30 '14 at 10:39
  • Glad you found the answer looks like we both were on the same page - not sure if my views_embed_view helped any our if you were already familiar – Sitori May 21 '14 at 19:11
1

It took me a while to find out how to do it in Drupal 8, and since this post is one of the first google hits I'll add the solution here:

function MODULE_form_node_NODETYPE_alter(&$form, FormStateInterface $form_state, $form_id) {
    ...
    $form['my_embedded_view'] = [
        '#type' => 'view',
        '#name' => 'my_view_name',
        '#display_id' => 'block_1',
        '#arguments' => [
            'arg1' => $arg_1,
            'arg2' => $arg_2,
        ],
        '#weight' => 30,
    ] ;
...
}

I used a block display for the view, I don't know if it's relevant.

  • Well, that doesn't work either: I was trying to accomplish exactly the same thing as Madam Adam, namely, to be able to edit the node and related entities brought in by the view, using the module views_entity_form_field. But the latter takes over the submit from the node edit page, so that the node cannot be modified. I made a few attempts to correct this problem, then I had to revert to the use of a custom page. – Francesco Marchetti-Stasi May 8 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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