public KeyValueEntityStorage::doCreate(array $values = array())
Performs storage-specific creation of entities.
Parameters
array $values: An array of values to set, keyed by property name.
Return value
\Drupal\Core\Entity\EntityInterface
Overrides EntityStorageBase::doCreate
File
- core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php, line 89
Class
- KeyValueEntityStorage
- Provides a key value backend for entities.
Namespace
Drupal\Core\Entity\KeyValueStore
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | public function doCreate( array $values = array ()) { // Set default language to site default if not provided. $values += array ( $this ->getEntityType()->getKey( 'langcode' ) => $this ->languageManager->getDefaultLanguage()->getId()); $entity = new $this ->entityClass( $values , $this ->entityTypeId); // @todo This is handled by ContentEntityStorageBase, which assumes // FieldableEntityInterface. The current approach in // https://www.drupal.org/node/1867228 improves this but does not solve it // completely. if ( $entity instanceof FieldableEntityInterface) { foreach ( $entity as $name => $field ) { if (isset( $values [ $name ])) { $entity -> $name = $values [ $name ]; } elseif (! array_key_exists ( $name , $values )) { $entity ->get( $name )->applyDefaultValue(); } unset( $values [ $name ]); } } return $entity ; } |
Please login to continue.