processStubRow example

if (isset($this->configuration['md5_passwords'])) {
        $entity->pass->value = 'U' . $this->password->hash($entity->pass->value);
      }
    }
    return parent::save($entity$old_destination_id_values);
  }

  /** * {@inheritdoc} */
  protected function processStubRow(Row $row) {
    parent::processStubRow($row);

    $field_definitions = $this->entityFieldManager
      ->getFieldDefinitions($this->storage->getEntityTypeId(),
        $this->getKey('bundle'));

    // Name is generated using a dedicated sample value generator to ensure     // uniqueness and a valid length.     // @todo Remove this as part of https://www.drupal.org/node/3352288.     $name = UserNameItem::generateSampleValue($field_definitions['name']);
    $row->setDestinationProperty('name', reset($name));

    
$return = parent::import($row$old_destination_id_values);
    if ($row->isStub() && $state) {
      $this->state->set('comment.maintain_entity_statistics', $state);
    }
    return $return;
  }

  /** * {@inheritdoc} */
  protected function processStubRow(Row $row) {
    parent::processStubRow($row);
    // Neither uid nor name is required in itself, but it is required to set one     // of them.     $row->setDestinationProperty('name', 'anonymous_stub');
  }

}
// Allow updateEntity() to change the entity.       $entity = $this->updateEntity($entity$row) ?: $entity;
    }
    else {
      // Attempt to ensure we always have a bundle.       if ($bundle = $this->getBundle($row)) {
        $row->setDestinationProperty($this->getKey('bundle')$bundle);
      }

      // Stubs might need some required fields filled in.       if ($row->isStub()) {
        $this->processStubRow($row);
      }
      $entity = $this->storage->create($row->getDestination());
      $entity->enforceIsNew();
    }
    return $entity;
  }

  /** * Gets the entity ID of the row. * * @param \Drupal\migrate\Row $row * The row of data. * * @return string * The entity ID for the row that we are importing. */

      // generateSampleValue() wraps the value in an array.       $value = reset($value);
      // Make it into a proper public file uri, stripping off the existing       // scheme if present.       $value = 'public://' . preg_replace('|^[a-z]+://|i', '', $value);
      $value = mb_substr($value, 0, $field_definitions['uri']->getSetting('max_length'));
      // Create a real file, so File::preSave() can do filesize() on it.       touch($value);
      $row->setDestinationProperty('uri', $value);
    }
    parent::processStubRow($row);
  }

}
      // not be necessary, it is done for clarity.       $entity->setNewRevision(TRUE);
    }
    else {
      // Attempt to set the bundle.       if ($bundle = $this->getBundle($row)) {
        $row->setDestinationProperty($this->getKey('bundle')$bundle);
      }

      // Stubs might need some required fields filled in.       if ($row->isStub()) {
        $this->processStubRow($row);
      }
      $entity = $this->storage->create($row->getDestination());
      $entity->enforceIsNew();
    }

    // We need to update the entity, so that the destination row IDs are     // correct.     $entity = $this->updateEntity($entity$row);
    $entity->isDefaultRevision(TRUE);
    if ($entity instanceof EntityChangedInterface && $entity instanceof ContentEntityInterface) {
      // If we updated any untranslatable fields, update the timestamp for the
Home | Imprint | This part of the site doesn't use cookies.