本文整理汇总了PHP中Drupal\Core\Entity\EntityForm::buildEntity方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityForm::buildEntity方法的具体用法?PHP EntityForm::buildEntity怎么用?PHP EntityForm::buildEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityForm
的用法示例。
在下文中一共展示了EntityForm::buildEntity方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildEntity
/**
* {@inheritdoc}
*/
public function buildEntity(array $form, FormStateInterface $form_state)
{
$entity = parent::buildEntity($form, $form_state);
$tags = array_map('trim', explode(',', $entity->get('tags')));
$entity->set('tags', $tags);
return $entity;
}
示例2: buildEntity
/**
* {@inheritdoc}
*/
public function buildEntity(array $form, FormStateInterface $form_state)
{
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = parent::buildEntity($form, $form_state);
// Mark the entity as requiring validation.
$entity->setValidationRequired(!$form_state->getTemporaryValue('entity_validated'));
return $entity;
}
示例3: buildEntity
/**
* {@inheritdoc}
*/
public function buildEntity(array $form, FormStateInterface $form_state)
{
// Save period.
$type = Schedule::getPeriodType($form_state->getValue('period_type'));
$seconds = Schedule::periodToSeconds(['number' => $form_state->getValue('period_number'), 'type' => $type]);
$form_state->setValue('period', $seconds);
return parent::buildEntity($form, $form_state);
}
示例4: buildEntity
/**
* {@inheritdoc}
*/
public function buildEntity(array $form, FormStateInterface $form_state) {
$entity = parent::buildEntity($form, $form_state);
// Update the link type plugin.
// @todo Do this somewhere else?
$entity->setLinkTypePlugin($entity->get('link_type'));
//debug($entity->getLinkTypePlugin()->getPluginId(), $entity->get('link_type'));
return $entity;
}
示例5: buildEntity
/**
* {@inheritdoc}
*/
public function buildEntity(array $form, FormStateInterface $form_state)
{
// Save field cardinality.
if ($form_state->getValue('cardinality') === 'number' && $form_state->getValue('cardinality_number')) {
$form_state->setValue('cardinality', $form_state->getValue('cardinality_number'));
}
return parent::buildEntity($form, $form_state);
}
示例6: buildEntity
/**
* {@inheritDoc}
*/
public function buildEntity(array $form, FormStateInterface $form_state)
{
/** @var \Drupal\pathauto\PathautoPatternInterface $entity */
$entity = parent::buildEntity($form, $form_state);
$default_weight = 0;
$alias_type = $entity->getAliasType();
if ($alias_type->getDerivativeId() && $this->entityTypeManager->hasDefinition($alias_type->getDerivativeId())) {
$entity_type = $alias_type->getDerivativeId();
// First, remove bundle and language conditions.
foreach ($entity->getSelectionConditions() as $condition_id => $condition) {
if (in_array($condition->getPluginId(), ['entity_bundle:' . $entity_type, 'node_type', 'language'])) {
$entity->removeSelectionCondition($condition_id);
}
}
if ($bundles = array_filter((array) $form_state->getValue('bundles'))) {
$default_weight -= 5;
$plugin_id = $entity_type == 'node' ? 'node_type' : 'entity_bundle:' . $entity_type;
$entity->addSelectionCondition(['id' => $plugin_id, 'bundles' => $bundles, 'negate' => FALSE, 'context_mapping' => [$entity_type => $entity_type]]);
}
if ($languages = array_filter((array) $form_state->getValue('languages'))) {
$default_weight -= 5;
$language_mapping = $entity_type . ':' . $this->entityTypeManager->getDefinition($entity_type)->getKey('langcode') . ':language';
$entity->addSelectionCondition(['id' => 'language', 'langcodes' => array_combine($languages, $languages), 'negate' => FALSE, 'context_mapping' => ['language' => $language_mapping]]);
$entity->addRelationship($language_mapping, t('Language'));
}
}
$entity->setWeight($default_weight);
return $entity;
}
示例7: buildEntity
/**
* {@inheritdoc}
*/
public function buildEntity(array $form, FormStateInterface $form_state)
{
/** @var \Drupal\menu_link_config\Entity\MenuLinkConfig $entity */
$entity = parent::buildEntity($form, $form_state);
$new_definition = $this->extractFormValues($form, $form_state);
$entity->id = $new_definition['metadata']['entity_id'];
$entity->parent = $new_definition['parent'];
$entity->menu_name = $new_definition['menu_name'];
$entity->setStatus(!$new_definition['hidden']);
$entity->expanded = $new_definition['expanded'];
$entity->weight = $new_definition['weight'];
$entity->url = $new_definition['url'];
$entity->route_name = $new_definition['route_name'];
$entity->route_parameters = $new_definition['route_parameters'];
$entity->options = $new_definition['options'];
return $entity;
}