Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 293522

Fix assumption that field settings is not a nested array

$
0
0

Updated: Comment #0

Problem/Motivation

Follow-up from #2136197-75: Move field/instance/widget/formatter settings out of annotation / plugin definition.

Currently this code assumes that field settings always have values as plain structure

+++ b/core/lib/Drupal/Core/TypedData/TypedDataManager.php
@@ -259,6 +259,13 @@ public function getPropertyInstance(TypedDataInterface $object, $property_name,
     }
     $key = $definition->getDataType();
     if ($settings = $definition->getSettings()) {
+      // Do not throw notices if settings values is array.
+      foreach ($settings as $k => $v) {
+        if (is_array($v)) {
+          debug($v, "key: $k");
+          $settings[$k] = ''; // stub for array settings or maybe serialize?
+        }
+      }
       $key .= ':' . implode(',', $settings);
     }
     $key .= ':' . $object->getPropertyPath() . '.';

This implode() throws notice:
Array to string conversionimplode(',', Array) Drupal\Core\TypedData\TypedDataManager->getPropertyInstance(Object, 0, NULL) Drupal\Core\TypedData\Plugin\DataType\ItemList->createItem(0) Drupal\Core\Field\FieldItemList->__construct(Object, NULL, NULL) Drupal\Core\TypedData\TypedDataManager->createInstance('list', Array) Drupal\Core\TypedData\TypedDataManager->create(Object) Drupal\system\Tests\Entity\EntityFieldTest->testEntityConstraintValidation() Drupal\simpletest\TestBase->run() simpletest_script_run_one_test('227', 'Drupal\system\Tests\Entity\EntityFieldTest')

Proposed resolution

Allow field settings with nested arrays,

Remaining tasks

Find a way to replace implode() or refactor this code

User interface changes

no

API changes

no


Viewing all articles
Browse latest Browse all 293522

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>