本文整理匯總了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;
}