本文整理汇总了PHP中Drupal\Core\Entity\EntityInterface::hasField方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityInterface::hasField方法的具体用法?PHP EntityInterface::hasField怎么用?PHP EntityInterface::hasField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityInterface
的用法示例。
在下文中一共展示了EntityInterface::hasField方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateRequestAttributes
/**
* Validates request attributes.
*/
protected function validateRequestAttributes(EntityInterface $entity, $field_name, $langcode)
{
// Validate the field name and language.
if (!$field_name || !$entity->hasField($field_name)) {
return FALSE;
}
if (!$langcode || !$entity->hasTranslation($langcode)) {
return FALSE;
}
return TRUE;
}
示例2: getChangedFieldName
/**
* Returns the name of the field that implements the changed timestamp.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity being tested.
*
* @return string
* The the field name.
*/
protected function getChangedFieldName($entity)
{
return $entity->hasField('content_translation_changed') ? 'content_translation_changed' : 'changed';
}
示例3: setChangedTime
/**
* {@inheritdoc}
*/
public function setChangedTime($timestamp)
{
$field_name = $this->translation->hasField('content_translation_changed') ? 'content_translation_changed' : 'changed';
$this->translation->set($field_name, $timestamp);
return $this;
}
示例4: updateAlias
/**
* {@inheritdoc}
*/
public function updateAlias(EntityInterface $entity, $op, array $options = array())
{
// Skip if the entity does not have the path field.
if (!$entity instanceof ContentEntityInterface || !$entity->hasField('path')) {
return NULL;
}
// Skip if pathauto processing is disabled.
if (isset($entity->path->pathauto) && empty($entity->path->pathauto) && empty($options['force'])) {
return NULL;
}
$options += array('language' => $entity->language()->getId());
$type = $entity->getEntityTypeId();
$bundle = $entity->bundle();
// Skip processing if the entity has no pattern.
if (!$this->getPatternByEntity($type, $bundle, $options['language'])) {
return NULL;
}
// Deal with taxonomy specific logic.
if ($type == 'taxonomy_term') {
$config_forum = $this->configFactory->get('forum.settings');
if ($entity->getVocabularyId() == $config_forum->get('vocabulary')) {
$type = 'forum';
}
}
$result = $this->createAlias($type, $op, '/' . $entity->urlInfo()->getInternalPath(), array($type => $entity), $bundle, $options['language']);
if ($type == 'taxonomy_term' && empty($options['is_child'])) {
// For all children generate new aliases.
$options['is_child'] = TRUE;
unset($options['language']);
foreach ($this->getTermTree($entity->getVocabularyId(), $entity->id(), NULL, TRUE) as $subterm) {
$this->updateAlias($subterm, $op, $options);
}
}
return $result;
}
示例5: updateEntityAlias
/**
* {@inheritdoc}
*/
public function updateEntityAlias(EntityInterface $entity, $op, array $options = array())
{
// Skip if the entity does not have the path field.
if (!$entity instanceof ContentEntityInterface || !$entity->hasField('path')) {
return NULL;
}
// Skip if pathauto processing is disabled.
if ($entity->path->pathauto != PathautoState::CREATE && empty($options['force'])) {
return NULL;
}
$options += array('language' => $entity->language()->getId());
$type = $entity->getEntityTypeId();
// Skip processing if the entity has no pattern.
if (!$this->getPatternByEntity($entity)) {
return NULL;
}
// Deal with taxonomy specific logic.
// @todo Update and test forum related code.
if ($type == 'taxonomy_term') {
$config_forum = $this->configFactory->get('forum.settings');
if ($entity->getVocabularyId() == $config_forum->get('vocabulary')) {
$type = 'forum';
}
}
try {
$result = $this->createEntityAlias($entity, $op);
} catch (\InvalidArgumentException $e) {
drupal_set_message($e->getMessage(), 'error');
return NULL;
}
// @todo Move this to a method on the pattern plugin.
if ($type == 'taxonomy_term') {
foreach ($this->loadTermChildren($entity->id()) as $subterm) {
$this->updateEntityAlias($subterm, $op, $options);
}
}
return $result;
}
示例6: initIsTranslating
/**
* Initializes the translation form state.
*
* @param \Drupal\Core\Form\FormStateInterface $form_state
* @param \Drupal\Core\Entity\EntityInterface $host
*/
protected function initIsTranslating(FormStateInterface $form_state, EntityInterface $host)
{
if ($this->isTranslating != NULL) {
return;
}
$this->isTranslating = FALSE;
if (!$host->isTranslatable()) {
return;
}
if (!$host->getEntityType()->hasKey('default_langcode')) {
return;
}
$default_langcode_key = $host->getEntityType()->getKey('default_langcode');
if (!$host->hasField($default_langcode_key)) {
return;
}
if (!empty($form_state->get('content_translation'))) {
// Adding a language through the ContentTranslationController.
$this->isTranslating = TRUE;
}
if ($host->hasTranslation($form_state->get('langcode')) && $host->getTranslation($form_state->get('langcode'))->get($default_langcode_key)->value == 0) {
// Editing a translation.
$this->isTranslating = TRUE;
}
}