I have created a wishlist in which those nodes are showing which are flagged, Wishlist working fine

The next task is to create favorite groups. That is, the user must be able to create groups of favorites, being able to edit a name, for example “summer recipes”, and assign recipes to the group.

What i have tried so far i have created a another content type "Create Group" which is automatically get flagged on creation by Using hook_node_presave().

Now flagged nodes(Groups) are also showing in wishlist then i have added draggable views into the existing wishlist view for grouping content by drag and drop by changing order.

But after changing order ,the changed order is not shaving into database,i think its a module issue which is not compactible with views relation.

Is there any alternative like is it possible to add custom select list in group content type which will show list of flagged node per user .

  • It sounds like you want your users to be able to create their own flags. Is that right? Then use Draggable views to allow them to sort it.
    – prkos
    Commented Nov 21, 2018 at 13:23
  • By draggable view or some other approach ,user should be able to create group and assign whislist nodes into it as per his choice above was mine own way to do the same.
    – user52318
    Commented Nov 21, 2018 at 13:28
  • what you suggest ?
    – user52318
    Commented Nov 21, 2018 at 13:28
  • I didnt understand what you're doing with hook node presave, but using a separate content type might be the way to go. Create an entity reference field, allow unlimited values, so users can reference nodes inot their Group list. Users will be able to rearrange the nodes they add to that field because multivalued fields come with that type of a widget.
    – prkos
    Commented Nov 21, 2018 at 13:33
  • Is it. possible to add custom select list in group content type in which i can slow flagged node per user
    – user52318
    Commented Nov 21, 2018 at 16:15

2 Answers 2


You can group existing flagged content into smaller groups through the Content type Group you created with the help of Views display type Entity reference.

  1. Create Content Views listing nodes that user might flag, don't create Page nor Block display, then when you save the View add the Display Entity reference from the Add dropdown.
  2. Under Format: Entity Reference list Settings choose Content: Title as the Search field

    In the results you should now see a list of node titles that can be flagged.

  3. Add a new Relationship Content flag from the Flag category and configure it:
    Tick Include only flagged content
    Flag Bookmark (or whatever the name of your flag is)
    By Current user

    This will now filter out only the nodes that are already flagged by the current user. You are probably logged in as admin so you will now only see nodes that admin has bookmarked.

  4. Adjust other views settings (Pager for example to show all items), No results behavior to You haven't bookmarked any content yet and save the View.
  5. Edit your Group content type and add a new Reference field that references unlimited number of Content (nodes).

    You'll probably want to make it a Required field

    Under Reference type Reference method choose the Views you created in the first step. You will only see views displays of Entity reference type here.

    A new option will appear View used to select the entities. Choose your exact views display here.

    There are no arguments to pass, leave that empty (it is done through the flag relationship).

  6. On the Manage form display settings for that field choose Check boxes/radio buttons.

Now when your users go to create a new Group node, they will be able to choose from a list of nodes they had already flagged:

Views Entity reference Flags current user

In case you need your users to control the order in which the selected nodes appear in the Group you can change the field widget to Autocomplete, that way the choices can be reordered:

Views Entity reference Flags current user Autocomplete

but this way the users have to search for node titles. You can help them by duplicating the views into a Block display and displaying it only on Create/Edit Group pages so users can see which title to search for.

  • Great solution very usefull ,thank you so much for great help
    – user52318
    Commented Nov 22, 2018 at 7:03
  • I cant believe is it possible with drupal amazing stuff
    – user52318
    Commented Nov 22, 2018 at 7:18
  • And we've only barely scratched the surface :)
    – prkos
    Commented Nov 22, 2018 at 16:48

Other way to do the same by using custom module (hook_form_alter).

function nestle_viewalter_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {


$x = db_query("SELECT title FROM {node_field_data} AS nfd WHERE nfd.type = :nid", array(':nid'=> $entity_id))->fetchAll();

if($form_id == "node_recipe_edit_form" ){
$node = $form_state->getFormObject()->getEntity();
$nid = $node->id();
$value_whishlist = db_select('custom_whislist', 'cw')
             ->fields('cw', ['whislist'])
             ->condition('node_id', $nid)

foreach ($x as $s)



if($form_id == "node_recipe_form" || $form_id == "node_recipe_edit_form" )
    $form['whislist'] =[

    '#type' =>'select',
    '#title' =>t('Choose whislist item'),
    '#options' =>$v,
    '#multiple' => true,
    '#default_value' =>!empty($value_whishlist) ? $value_whishlist : '',

foreach (array_keys($form['actions']) as $action) {
if ($action != 'preview' && isset($form['actions'][$action]['#type']) && $form['actions'][$action]['#type'] === 'submit') {
  $form['actions'][$action]['#submit'][] = 'nestle_viewalter_form_submit';
 function nestle_viewalter_form_submit(array $form, FormStateInterface $form_state){
$node = $form_state->getFormObject()->getEntity();
$nid = $node->id();
$path = \Drupal::request()->getpathInfo();
$arg  = explode('/',$path);
if ($arg[3] == 'edit'){
    $delete = db_delete('custom_whislist')
    ->condition('node_id', $nid)


foreach($form_state->getValue('whislist') as $val){
        $query = db_insert('custom_whislist')
        'node_id'=> $nid

($arg[3] == 'edit') ? $form_state->setRedirectUrl(new Url('entity.node.canonical', array('node' => $nid))) : '';

Your Answer

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