src/Service/NT8PropertyService.php
public function updateNodeInstanceFromData(array $updatedValues, EntityInterface &$nodeInstance) {
    $updated = FALSE;

    // Compare for differences and update if a difference is found.
    foreach ($updatedValues as $updatedValueKey => $updatedValue) {
      $currentNodeField = static::getNodeFieldValue($nodeInstance, $updatedValueKey);

      $length_of_update_fields = count($updatedValue);

      $updateIndex = 0;

      // For each field on the current node.
      // Iterate through the child entries attached to the field.
      // This works for all fields even those with cardinality: 1.
      foreach ($currentNodeField as $index => $nodeFieldValue) {
        $comparisonUpdate = $updatedValue;

        // If the field has more than 1 entries.
        // Set the comparison to the value of the current entry.
        // We keep track of current entry by incrementing the `updateIndex` var.
        if ($length_of_update_fields > 1) {
          $comparisonUpdate = $updatedValue[$updateIndex++] ?? $updatedValue;
        }

        // Sometimes the data to compare is nested another level deep.
        // This retrieves it and lets us continue as if it were a flat array.
        $nestedComparison = $comparisonUpdate[0] ?? NULL;
        if ($nestedComparison && is_array($nestedComparison)) {
          // @codeCoverageIgnoreStart
          $comparisonUpdate = $nestedComparison;
          // @codeCoverageIgnoreEnd
        }

        // Sort both arrays so the equality check below evaluates correctly.
        sort($comparisonUpdate);
        sort($nodeFieldValue);

        // Compare the two field entries for differences.
        $difference = ($comparisonUpdate == $nodeFieldValue);

        if ($difference == 0) {
          // If a difference is found update the whole field entry.
          $fieldRef = static::getNodeField($nodeInstance, $updatedValueKey);
          $fieldRef->setValue($updatedValue);

          // We should only save if $updated is equal to TRUE.
          $updated = TRUE;
        }
      }
    }

    return $updated;
  }
public function updateNodeInstanceFromData(array $updatedValues, EntityInterface &$nodeInstance) {
    $updated = FALSE;

    // Compare for differences and update if a difference is found.
    foreach ($updatedValues as $updatedValueKey => $updatedValue) {
      $currentNodeField = static::getNodeFieldValue($nodeInstance, $updatedValueKey);

      $length_of_update_fields = count($updatedValue);

      $updateIndex = 0;

      // For each field on the current node.
      // Iterate through the child entries attached to the field.
      // This works for all fields even those with cardinality: 1.
      foreach ($currentNodeField as $index => $nodeFieldValue) {
        $comparisonUpdate = $updatedValue;

        // If the field has more than 1 entries.
        // Set the comparison to the value of the current entry.
        // We keep track of current entry by incrementing the `updateIndex` var.
        if ($length_of_update_fields > 1) {
          $comparisonUpdate = $updatedValue[$updateIndex++] ?? $updatedValue;
        }

        // Sometimes the data to compare is nested another level deep.
        // This retrieves it and lets us continue as if it were a flat array.
        $nestedComparison = $comparisonUpdate[0] ?? NULL;
        if ($nestedComparison && is_array($nestedComparison)) {
          // @codeCoverageIgnoreStart
          $comparisonUpdate = $nestedComparison;
          // @codeCoverageIgnoreEnd
        }

        // Sort both arrays so the equality check below evaluates correctly.
        sort($comparisonUpdate);
        sort($nodeFieldValue);

        // Compare the two field entries for differences.
        $difference = ($comparisonUpdate == $nodeFieldValue);

        if ($difference == 0) {
          // If a difference is found update the whole field entry.
          $fieldRef = static::getNodeField($nodeInstance, $updatedValueKey);
          $fieldRef->setValue($updatedValue);

          // We should only save if $updated is equal to TRUE.
          $updated = TRUE;
        }
      }
    }

    return $updated;
  }
public function updateNodeInstanceFromData ( array $ updatedValues , EntityInterface & $ nodeInstance ) { $ updated = FALSE ; // Compare for differences and update if a difference is found. foreach ( $ updatedValues as $ updatedValueKey => $ updatedValue ) { $ currentNodeField = static :: getNodeFieldValue ( $ nodeInstance , $ updatedValueKey ) ; $ length_of_update_fields = count ( $ updatedValue ) ; $ updateIndex = 0 ; // For each field on the current node. // Iterate through the child entries attached to the field. // This works for all fields even those with cardinality: 1. foreach ( $ currentNodeField as $ index => $ nodeFieldValue ) { $ comparisonUpdate = $ updatedValue ; // If the field has more than 1 entries. // Set the comparison to the value of the current entry. // We keep track of current entry by incrementing the `updateIndex` var. if ( $ length_of_update_fields > 1 ) { $ comparisonUpdate = $ updatedValue [ $ updateIndex ++ ] ?? $ updatedValue ; } // Sometimes the data to compare is nested another level deep. // This retrieves it and lets us continue as if it were a flat array. $ nestedComparison = $ comparisonUpdate [ 0 ] ?? NULL ; if ( $ nestedComparison && is_array ( $ nestedComparison ) ) { // @codeCoverageIgnoreStart $ comparisonUpdate = $ nestedComparison ; // @codeCoverageIgnoreEnd } // Sort both arrays so the equality check below evaluates correctly. sort ( $ comparisonUpdate ) ; sort ( $ nodeFieldValue ) ; // Compare the two field entries for differences. $ difference = ( $ comparisonUpdate == $ nodeFieldValue ) ; if ( $ difference == 0 ) { // If a difference is found update the whole field entry. $ fieldRef = static :: getNodeField ( $ nodeInstance , $ updatedValueKey ) ; $ fieldRef -> setValue ( $ updatedValue ) ; // We should only save if $updated is equal to TRUE. $ updated = TRUE ; } } } return $ updated ; }
Updates an EntityInterface from a provided array of updated values.

@param array $updatedValues
Array of updated values to be compared against.
@param \Drupal\Core\Entity\EntityInterface $nodeInstance
Instance of the node which has the fields to compare against.

@return bool
Indicates that field(s) have been changed on the node.
Updates an EntityInterface from a provided array of updated values .