Chris@0: generateEntity($value); Chris@0: } Chris@0: Chris@0: return $result; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Generates stub entity for a given value. Chris@0: * Chris@0: * @param string $value Chris@0: * Value to use in creation of stub entity. Chris@0: * Chris@0: * @return int|string Chris@0: * The entity id of the generated entity. Chris@0: */ Chris@0: protected function generateEntity($value) { Chris@0: if(!empty($value)) { Chris@0: $entity = $this->entityManager Chris@0: ->getStorage($this->lookupEntityType) Chris@0: ->create($this->stub($value)); Chris@0: $entity->save(); Chris@0: Chris@0: return $entity->id(); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Fabricate a stub entity. Chris@0: * Chris@0: * This is intended to be extended by implementing classes to provide for more Chris@0: * dynamic default values, rather than just static ones. Chris@0: * Chris@0: * @param $value Chris@0: * Value to use in creation of stub entity. Chris@0: * Chris@0: * @return array Chris@0: * The stub entity. Chris@0: */ Chris@0: protected function stub($value) { Chris@0: $stub = [$this->lookupValueKey => $value]; Chris@0: Chris@0: if ($this->lookupBundleKey) { Chris@0: $stub[$this->lookupBundleKey] = $this->lookupBundle; Chris@0: } Chris@0: Chris@0: // Gather any static default values for properties/fields. Chris@0: if (isset($this->configuration['default_values']) && is_array($this->configuration['default_values'])) { Chris@0: foreach ($this->configuration['default_values'] as $key => $value) { Chris@0: $stub[$key] = $value; Chris@0: } Chris@0: } Chris@0: Chris@0: return $stub; Chris@0: } Chris@0: Chris@0: }