本文整理汇总了PHP中Drupal\Core\Entity\EntityInterface::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityInterface::toArray方法的具体用法?PHP EntityInterface::toArray怎么用?PHP EntityInterface::toArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityInterface
的用法示例。
在下文中一共展示了EntityInterface::toArray方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toArray
/**
* {@inheritdoc}
*/
public function toArray()
{
if (!isset($this->entity)) {
throw new MissingDataException('Unable to get property values as no entity has been provided.');
}
return $this->entity->toArray();
}
示例2: getFormSubmitActionForNewTranslation
/**
* Returns the form action value when submitting a new translation.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity being tested.
* @param string $langcode
* Language code for the form.
*
* @return string
* Name of the button to hit.
*/
protected function getFormSubmitActionForNewTranslation(EntityInterface $entity, $langcode)
{
$entity->addTranslation($langcode, $entity->toArray());
return $this->getFormSubmitAction($entity, $langcode);
}
示例3: mapToStorageRecord
/**
* Maps from an entity object to the storage record.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity object.
*
* @return array
* The record to store.
*/
protected function mapToStorageRecord(EntityInterface $entity)
{
return $entity->toArray();
}
示例4: doSave
/**
* {@inheritdoc}
*/
protected function doSave($id, EntityInterface $entity)
{
$is_new = $entity->isNew();
// Save the entity data in the key value store.
$this->keyValueStore->set($entity->id(), $entity->toArray());
// If this is a rename, delete the original entity.
if ($this->has($id, $entity) && $id !== $entity->id()) {
$this->keyValueStore->delete($id);
}
return $is_new ? SAVED_NEW : SAVED_UPDATED;
}
示例5: doSave
/**
* {@inheritdoc}
*/
protected function doSave($id, EntityInterface $entity)
{
$is_new = $entity->isNew();
$prefix = $this->getConfigPrefix();
if ($id !== $entity->id()) {
// Renaming a config object needs to cater for:
// - Storage needs to access the original object.
// - The object needs to be renamed/copied in ConfigFactory and reloaded.
// - All instances of the object need to be renamed.
$config = $this->configFactory->rename($prefix . $id, $prefix . $entity->id());
} else {
$config = $this->configFactory->get($prefix . $id);
}
// Retrieve the desired properties and set them in config.
foreach ($entity->toArray() as $key => $value) {
$config->set($key, $value);
}
$config->save();
return $is_new ? SAVED_NEW : SAVED_UPDATED;
}