7 – How to allow users to ‘add’ values to a multi-value field but not edit any previously add values?

I have a field called ‘Remarks’ on an ECK entity (not a node) and Role A is allowed to leave remarks but I don’t want them to edit previous remarks, I just want to give them the option to add one. Note: they are not the author or owner of the entity. Right now, I use an Edit Page Variant for this entity that they have access to and where this form for ‘field_remarks’ appears. The problem is that the previously added remarks are still showing up and therefore now they can still edit someone else’s remarks.

potential solution 1

I would probably be possible to hide the fields that already contain values with jQuery but that is not really the Drupal way, I believe.

potential solution 2

Could it possibly be done with a Rules component that adds the value (text) to this field programmatically? And if so, how and where to show a text field that would accomplish that?

8 – Count multivalue image field values in views-view-fields.html.twig

Making a presentation template for the gallery. The photo gallery has an image field with multiple values. I need to output the number of gallery photos (in the field_gallery_photo). How do I do this? I tried adding a field with a photo to the view, and all the values are shown in one line. The result is not accurate:

{{ fields.field_gallery_photo.content | length }}

8 – Migrating multivalue link fields from CSV

I am trying to migrate data from D7 to D8 using Drupal Migrate with source CSV. I am able to import all the data except multivalue link field. With the help of examples from Migrate Plus, I am able to import single value to it. But its not happening with multiple value.

The CSV file is like this

title,related_links_title,related_links_url
"Node 1","Link Title 1, Link Title 2, Link Title 3","http://www.google.com, http://www.google.com, http://www.google.com"
"Node 2","Link Title 1, Link Title 2, Link Title 3, Link Title 4","http://www.google.com, http://www.google.com, http://www.google.com, http://www.google.com"

And the migration file looks like this:

process:
  field_related_links/uri: related_links_url
  field_related_links/title: related_links_title

When I run this migration, I am not getting any errors but all the data is coming in a single field rather than splitting it to multiple fields. Do I need to create a subprocess to handle this?

8 – How can I attach an image from an existing image field to another multi-value image field?

I have the nodes that have the source image field field_old_image_field and the destination image field, field_new_image_field. field_old_image_fieldhas only one image. field_new_image_fieldcan have multiple images and probably does. I need to copy the image from field_old_image_field to field_new_image_field without disturbing the images that are already in field_new_image_field.

Here’s my code so far:

foreach ($nodes as $node) {  
    if ($node->hasField('field_old_image_field') && !empty($node->field_old_image_field->target_id)) {
      $image = $node->get('field_old_image_field');
      $image_uri = $image->entity->getFileUri();
      $image_alt = $image(0)->get('alt')->getString();
      $image_title = $image(0)->get('title')->getString();

      $node->get('field_new_image_field')->appendItem((
        'target_id' => $image,
        'alt' => $image_alt,
        'title' => $image_title,
      ));
    }

    $node->save();
  }

But when I run this code in an update hook, I get

In EntityReference.php line 106:

Value is not a valid entity.

I was getting it to work earlier, but I wasn’t getting the alt text or the title text copied over. What’s wrong with this code and is there an easier way to do this?

8 – Programmatically set the format for each value of a multi-value text field

I am trying to programmatically set the format of a multi value text field to ‘full_html’.

I have tried:

$Links = array (1, 2, 3, 4, 5);

$node->field_article_links() = $Links;
$node->field_article_links->format = 'full_html';
$node->save();

and

$Links = array (1, 2, 3, 4, 5);

foreach ($Links as $Link) {
$node->set('field_article_links', $Link);
$node->field_article_links->format = 'full_html';
}
$node->save();

But the results are always the same, only the format of the first value of the field is set to ‘full_html’ and the others remain unchanged.

node edit

What am i doing wrong ?

8 – Add new items to a multivalue field instead of override existing values

I have an article content type with a multi-values taxonomy reference field field_article_countries referencing the vocabulary Countries.

And also I have a book content type with a multi-values taxonomy reference field field_book_countries referencing the same vocabulary Countries.

I am trying to:

Loop through all loaded articles one by one.
2. Get all values of field_article_countries
3. Set those values to field_book_countries
4. Save the loaded book node.

Example:

1) Book of nid: 12 has field_book_countries set to none.

2) Article of nid: 3 has field_article_countries set to:

3) and Article of nid: 40 has field_article_countries set to:

  • Greece
  • Turkey
  • Egypt
  • Brazil
  • Spain

I want to:

  1. Load article nid: 3
  2. Get the values of field_article_countries which is italy
  3. Load book nid: 12 and set the value of field_book_countries to:
    italy
  4. Load article nid: 40
  5. Get the values of field_article_countries which are: greece, turkey, egypt, brazil, spain
  6. Set the value of field_book_countries from book nid: 12 to:
    greece, turkey, egypt, brazil, spain + italy.
  7. Save book of nid: 12

So finally, field_book_countries from book of nid: 12 will have all below values:

  • Italy

  • Greece

  • Turkey

  • Egypt

  • Brazil

  • Spain

My code:

<?php

// ...

$articleIDs = (
  '3',
  '40'
);

// Load all articles.
$articles = DrupalnodeEntityNode::loadMultiple($articleIDs);

// Loop through loaded articles.
foreach ($articles as $article) {

    // Get the "Countries" Values.
    $countries = $article->get('field_article_countries')->getValue();

    // Set the 'countries' values to the node "book".
    $book->set('field_book_countries', $countries);
    //$book->field_book_countries() = ('target_id' => $countries);     // use array

    }

    // Save Book node.
    $book-->save();

However, for some reason and during the loop, the new values of ‘field_book_countries’ are overriding the existing one.

What am I doing wrong ?

8 – Do multi-level multi-value relationships work in one view?

In Drupal 8 I have a content type historywith a multi-valued entity reference to the content type Project, which in turn has a multi-value reference to Team memberthat has a monovalent reference to person. I want to display a list of projects in my story node and a list of team members in each.

I have an embedded view (content type history), to which I pass the nid as a context filter, whereby 3 relationships are defined: referenced Projects, referred Team membersand referenced people. I'm pretty sure I've added fields from all three types, each using the correct relationship.

I get Project Fields correct in each case Project in a row. But I don't get anything for it Team members or people.

Are you asking this view to do something that views cannot by having multi-level references on two levels? Is there a better approach? I miss something

How can a multi-value MongoDB field be used with SQL Server?

For example, I have a field in MondoDB like this:

"SignedDocs" : [

    { 
     "_id" : "blablabla"
     "title": " bla bla bla"
     },

    { 
     "_id" : "blablabla2"
     "title": " bla bla bla2"
     },

    { 
     "_id" : "blablabla3"
     "title": " bla bla bla3"
     }
]

So that you understand, there are 3 values ​​in this field. What would be the best way to do this with SQL Server? what is the best pratice 3 values ​​to store within a column. I don't want to do something like this:

NAME    | DOCSSIGNED 
abduh   |      1
abduh   |      2
abduh   |      3

There are many rows with the same values ​​that only change this DOCSSIGNED Field as FK, which points to the DOCS table.

EDIT: Ohh maybe a third table between these 2 that connects them?

Update a multi-value SharePoint lookup column using a PowerApps combobox

I have a primary SharePoint list linked to a custom PowerApps data entry form. In this form, I added an additional combo box with multiple selections that shows values ​​from a secondary SharePoint reference list. The main intent is for the user to select one or more values ​​from the combo box of the secondary reference list and then insert all of the selected values ​​into the search column attached to the primary SharePoint list record.

The problem is that when you save the primary record in PowerApps, only a single value is inserted back into the multivalued lookup column (in the primary list). I can confirm that the "Allows multiple values" option is checked in the lookup column.

I was hoping I could only use it cboReferenceList.SelectedItems in the update properties of the DataCard, but unfortunately it doesn't seem to work.

How can I make sure that all my combo box values ​​are saved back in my SharePoint lookup column?