joachim-n / mutable-typed-data

Typed data system with mutable properties
GNU General Public License v3.0
1 stars 2 forks source link

import() throws exceptions for bad variants #12

Open joachim-n opened 1 year ago

joachim-n commented 1 year ago

Docs for import() say it won't throw exceptions, but it does for bad variant values:

MutableTypedData\Exception\InvalidInputException: Invalid variant 'wsd_test.worker' at address module:plugins:0. in MutableTypedData\Data\MutableData->setVariant() (line 226 of /Users/joachim/Sites/multibasebox/projects/thewsd/vendor/joachim-n/mutable-typed-data/Data/MutableData.php).

MutableTypedData\Data\MutableData->onChange(Object, 'wsd_test.worker') (Line: 79)
MutableTypedData\Data\SimpleData->set('wsd_test.worker') (Line: 28)
MutableTypedData\Data\StringData->set('wsd_test.worker') (Line: 687)
MutableTypedData\Data\DataItem->import('wsd_test.worker') (Line: 270)
MutableTypedData\Data\ComplexData->import(Array) (Line: 308)
MutableTypedData\Data\ArrayData->import(Array) (Line: 270)
MutableTypedData\Data\ComplexData->import(Array) (Line: 117)
Drupal\module_builder\Form\ComponentFormBase->getComponentDataObject() (Line: 85)
joachim-n commented 1 year ago

MutableData needs:

  /**
   * {@inheritdoc}
   */
  public function import($value) {
    // Bail silently if setting the variant would fail.
    if (empty($value[$this->typePropertyName])) {
      return;
    }
    $mapping = $this->definition->getVariantMapping();
    if (!isset($mapping[$value[$this->typePropertyName]])) {
      return;
    }

    parent::import($value);
  }

and tests obv!