本文整理汇总了PHP中Drupal\Core\Entity\EntityManagerInterface::getFormModes方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManagerInterface::getFormModes方法的具体用法?PHP EntityManagerInterface::getFormModes怎么用?PHP EntityManagerInterface::getFormModes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityManagerInterface
的用法示例。
在下文中一共展示了EntityManagerInterface::getFormModes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addDefaultField
/**
* {@inheritdoc}
*/
public function addDefaultField($entity_type, $bundle, $field_name = 'comment', $default_value = CommentItemInterface::OPEN, $comment_type_id = 'comment')
{
$comment_type_storage = $this->entityManager->getStorage('comment_type');
if ($comment_type = $comment_type_storage->load($comment_type_id)) {
if ($comment_type->getTargetEntityTypeId() !== $entity_type) {
throw new \InvalidArgumentException(String::format('The given comment type id %id can only be used with the %entity_type entity type', array('%id' => $comment_type_id, '%entity_type' => $entity_type)));
}
} else {
// Silently create the comment-type for the calling code.
$comment_type_storage->create(array('id' => $comment_type_id, 'label' => Unicode::ucfirst($comment_type_id), 'target_entity_type_id' => $entity_type, 'description' => 'Default comment field'))->save();
}
// Make sure the field doesn't already exist.
if (!FieldStorageConfig::loadByName($entity_type, $field_name)) {
// Add a default comment field for existing node comments.
$field_storage = $this->entityManager->getStorage('field_storage_config')->create(array('entity_type' => $entity_type, 'field_name' => $field_name, 'type' => 'comment', 'translatable' => TRUE, 'settings' => array('comment_type' => $comment_type_id)));
// Create the field.
$field_storage->save();
}
// Make sure the instance doesn't already exist.
if (!array_key_exists($field_name, $this->entityManager->getFieldDefinitions($entity_type, $bundle))) {
$field = $this->entityManager->getStorage('field_config')->create(array('label' => 'Comments', 'description' => '', 'field_name' => $field_name, 'entity_type' => $entity_type, 'bundle' => $bundle, 'required' => 1, 'default_value' => array(array('status' => $default_value, 'cid' => 0, 'last_comment_name' => '', 'last_comment_timestamp' => 0, 'last_comment_uid' => 0))));
$field->save();
// Assign widget settings for the 'default' form mode.
entity_get_form_display($entity_type, $bundle, 'default')->setComponent($field_name, array('type' => 'comment_default', 'weight' => 20))->save();
// The comment field should be hidden in all other form displays.
foreach ($this->entityManager->getFormModes($entity_type) as $id => $form_mode) {
$display = entity_get_form_display($entity_type, $bundle, $id);
// Only update existing displays.
if ($display && !$display->isNew()) {
$display->removeComponent($field_name)->save();
}
}
// Set default to display comment list.
entity_get_display($entity_type, $bundle, 'default')->setComponent($field_name, array('label' => 'above', 'type' => 'comment_default', 'weight' => 20))->save();
// The comment field should be hidden in all other view displays.
foreach ($this->entityManager->getViewModes($entity_type) as $id => $view_mode) {
$display = entity_get_display($entity_type, $bundle, $id);
// Only update existing displays.
if ($display && !$display->isNew()) {
$display->removeComponent($field_name)->save();
}
}
}
$this->addBodyField($comment_type_id);
}
示例2: alterLocalTasks
/**
* Alters the base_route definition for field_ui local tasks.
*
* @param array $local_tasks
* An array of local tasks plugin definitions, keyed by plugin ID.
*/
public function alterLocalTasks(&$local_tasks)
{
foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
if ($route_name = $entity_type->get('field_ui_base_route')) {
$local_tasks["field_ui.fields:overview_{$entity_type_id}"]['base_route'] = $route_name;
$local_tasks["field_ui.fields:form_display_overview_{$entity_type_id}"]['base_route'] = $route_name;
$local_tasks["field_ui.fields:display_overview_{$entity_type_id}"]['base_route'] = $route_name;
$local_tasks["field_ui.fields:field_form_display_default_{$entity_type_id}"]['base_route'] = $route_name;
$local_tasks["field_ui.fields:field_display_default_{$entity_type_id}"]['base_route'] = $route_name;
foreach ($this->entityManager->getFormModes($entity_type_id) as $form_mode => $form_mode_info) {
$local_tasks['field_ui.fields:field_form_display_' . $form_mode . '_' . $entity_type_id]['base_route'] = $route_name;
}
foreach ($this->entityManager->getViewModes($entity_type_id) as $view_mode => $form_mode_info) {
$local_tasks['field_ui.fields:field_display_' . $view_mode . '_' . $entity_type_id]['base_route'] = $route_name;
}
}
}
}
示例3: alterLocalTasks
/**
* Alters the base_route definition for field_ui local tasks.
*
* @param array $local_tasks
* An array of local tasks plugin definitions, keyed by plugin ID.
*/
public function alterLocalTasks(&$local_tasks)
{
foreach ($this->entityManager->getDefinitions() as $entity_type => $entity_info) {
if ($entity_info->isFieldable() && $entity_info->hasLinkTemplate('admin-form')) {
$admin_form = $entity_info->getLinkTemplate('admin-form');
$local_tasks["field_ui.fields:overview_{$entity_type}"]['base_route'] = $admin_form;
$local_tasks["field_ui.fields:form_display_overview_{$entity_type}"]['base_route'] = $admin_form;
$local_tasks["field_ui.fields:display_overview_{$entity_type}"]['base_route'] = $admin_form;
$local_tasks["field_ui.fields:field_form_display_default_{$entity_type}"]['base_route'] = $admin_form;
$local_tasks["field_ui.fields:field_display_default_{$entity_type}"]['base_route'] = $admin_form;
foreach ($this->entityManager->getFormModes($entity_type) as $form_mode => $form_mode_info) {
$local_tasks['field_ui.fields:field_form_display_' . $form_mode . '_' . $entity_type]['base_route'] = $admin_form;
}
foreach ($this->entityManager->getViewModes($entity_type) as $view_mode => $form_mode_info) {
$local_tasks['field_ui.fields:field_display_' . $view_mode . '_' . $entity_type]['base_route'] = $admin_form;
}
}
}
}
示例4: getFormModes
/**
* {@inheritdoc}
*/
public function getFormModes($entity_type_id)
{
return $this->entityManager->getFormModes($entity_type_id);
}