本文整理汇总了PHP中Drupal\Core\Entity\EntityInterface::getFields方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityInterface::getFields方法的具体用法?PHP EntityInterface::getFields怎么用?PHP EntityInterface::getFields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityInterface
的用法示例。
在下文中一共展示了EntityInterface::getFields方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getProperties
/**
* {@inheritdoc}
*/
public function getProperties($include_computed = FALSE)
{
if (!isset($this->entity)) {
throw new MissingDataException('Unable to get properties as no entity has been provided.');
}
if (!$this->entity instanceof FieldableEntityInterface) {
// @todo: Add support for config entities in
// https://www.drupal.org/node/1818574.
return array();
}
return $this->entity->getFields($include_computed);
}
示例2: getHostConfiguration
function getHostConfiguration(EntityInterface $entity, $prefix = 'field_ran_')
{
// TODO: This can't be right... there must be an easier way to access a
// field collection's fields.
$field_collection = $entity->getFields()['field_ran_host_configuration']->getIterator()[0];
$fields = $field_collection->getFieldCollectionItem()->getFields();
$vars = array();
$len = strlen($prefix);
foreach ($fields as $name => $field) {
if (substr($name, 0, $len) == $prefix) {
$vars[substr($name, $len)] = array();
foreach ($field->getIterator() as $object) {
$vars[substr($name, $len)][] = $object->getString();
}
$vars[substr($name, $len)] = array_filter($vars[substr($name, $len)]);
}
}
return $vars;
}
示例3: get
/**
* Responds to entity GET requests.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity object.
*
* @return \Drupal\rest\ResourceResponse
* The response containing the entity with its accessible fields.
*
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
*/
public function get(EntityInterface $entity)
{
if (!$entity->access('view')) {
throw new AccessDeniedHttpException();
}
$fields = $entity->getFields();
$display_id = $entity->getEntityTypeId() . '.' . $entity->bundle() . '.restx';
// Remove hidden fields (Display mode 'default').
$view_display = \Drupal::entityManager()->getStorage('entity_view_display')->load($display_id);
if ($view_display) {
$content = $view_display->get('content');
foreach ($fields as $field_name => $field) {
if (!$field->access('view') || substr($field_name, 0, 6) === 'field_' && !isset($content[$field_name])) {
unset($fields[$field_name]);
}
}
}
$output = array('data' => $fields);
$response = new ResourceResponse($output, ResourceResponse::HTTP_OK);
$response->addCacheableDependency($output);
return $response;
}