MultiValueField

Component ID

2843446

Component name

MultiValueField

Component type

module

Maintenance status

Development status

Component security advisory coverage

not-covered

Downloads

168

Component created

Component changed

Component body

Multivaluefield

Multivaluefield (Multiple values field) is a drupal field plugin, allow to add multiple values on one field.

Add / Create node grammatically with a "Multivaluefield" field

Examples

Example 1.

Drupal
odeEntityNode::create(array(
  'type' => 'page',
  'title' => 'Mvf testing page',
  'status' => 1,
  'field_mvf' => [
    'index' => 'Test index 1',
    '0' => "Fields Value 1",
    '1' => "Fields Value 2",
  ],
))->save();

Example 2.

(With $nid = Previously created node ID)

$entity = Drupal
odeEntityNode::load($nid);
$values = [
  'index' => 'Test index 2',
  '0' => "Fields Value 3",
  '1' => "Fields Value 4",
];
$entity->set('field_mvf', [$values, $values]);
$entity->save();

Similar Projects

- Paragraphs (https://www.drupal.org/project/paragraphs)
- Field collection (https://www.drupal.org/project/field_collection)

Different from the Paragraphs and Field collection

Lite-weight
Store all values in the same field (JSON)
Field configuration is stored on field storage configuration.
No need to create separate configurations
....