本文整理汇总了PHP中Drupal\Core\Entity\Entity\EntityFormDisplay::collectRenderDisplay方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityFormDisplay::collectRenderDisplay方法的具体用法?PHP EntityFormDisplay::collectRenderDisplay怎么用?PHP EntityFormDisplay::collectRenderDisplay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\Entity\EntityFormDisplay
的用法示例。
在下文中一共展示了EntityFormDisplay::collectRenderDisplay方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
/**
* Initialize the form state and the entity before the first form build.
*/
protected function init(FormStateInterface $form_state)
{
// Ensure we act on the translation object corresponding to the current form
// language.
$langcode = $this->getFormLangcode($form_state);
$this->entity = $this->entity->getTranslation($langcode);
$form_display = EntityFormDisplay::collectRenderDisplay($this->entity, $this->getOperation());
$this->setFormDisplay($form_display, $form_state);
parent::init($form_state);
}
示例2: buildForm
/**
* {@inheritdoc]
*/
public function buildForm(array $form, FormStateInterface $form_state, EntityInterface $entity_1 = NULL, EntityInterface $entity_2 = NULL)
{
// First entity.
$form_state->set('entity_1', $entity_1);
$form_display_1 = EntityFormDisplay::collectRenderDisplay($entity_1, 'default');
$form_state->set('form_display_1', $form_display_1);
$form_display_1->buildForm($entity_1, $form, $form_state);
// Second entity.
$form_state->set('entity_2', $entity_2);
$form_display_2 = EntityFormDisplay::collectRenderDisplay($entity_2, 'default');
$form_state->set('form_display_2', $form_display_2);
$form['entity_2'] = array('#type' => 'details', '#title' => t('Second entity'), '#tree' => TRUE, '#parents' => array('entity_2'), '#weight' => 50);
$form_display_2->buildForm($entity_2, $form['entity_2'], $form_state);
$form['save'] = array('#type' => 'submit', '#value' => t('Save'), '#weight' => 100);
return $form;
}
示例3: buildForm
/**
* {@inheritdoc]
*/
public function buildForm(array $form, FormStateInterface $form_state, EntityInterface $entity_1 = NULL, EntityInterface $entity_2 = NULL)
{
// First entity.
$form_state->set('entity_1', $entity_1);
$form_display_1 = EntityFormDisplay::collectRenderDisplay($entity_1, 'default');
$form_state->set('form_display_1', $form_display_1);
$form_display_1->buildForm($entity_1, $form, $form_state);
// Second entity.
$form_state->set('entity_2', $entity_2);
$form_display_2 = EntityFormDisplay::collectRenderDisplay($entity_2, 'default');
$form_state->set('form_display_2', $form_display_2);
$form['entity_2'] = ['#type' => 'details', '#title' => t('Second entity'), '#tree' => TRUE, '#parents' => ['entity_2'], '#weight' => 50, '#attributes' => ['class' => ['entity-2']]];
$form_display_2->buildForm($entity_2, $form['entity_2'], $form_state);
if ($entity_2 instanceof EntityChangedInterface) {
// Changed must be sent to the client, for later overwrite error checking.
// @see Drupal\field\Tests\NestedFormTest::testNestedEntityFormEntityLevelValidation()
$form['entity_2']['changed'] = ['#type' => 'hidden', '#default_value' => $entity_1->getChangedTime()];
}
$form['save'] = array('#type' => 'submit', '#value' => t('Save'), '#weight' => 100);
return $form;
}
示例4: init
/**
* Initialize the form state and the entity before the first form build.
*/
protected function init(FormStateInterface $form_state, EntityInterface $entity, $field_name)
{
// @todo Rather than special-casing $node->revision, invoke prepareEdit()
// once https://www.drupal.org/node/1863258 lands.
if ($entity->getEntityTypeId() == 'node') {
$node_type = $this->nodeTypeStorage->load($entity->bundle());
$entity->setNewRevision($node_type->isNewRevision());
$entity->revision_log = NULL;
}
$form_state->set('entity', $entity);
$form_state->set('field_name', $field_name);
// Fetch the display used by the form. It is the display for the 'default'
// form mode, with only the current field visible.
$display = EntityFormDisplay::collectRenderDisplay($entity, 'default');
foreach ($display->getComponents() as $name => $options) {
if ($name != $field_name) {
$display->removeComponent($name);
}
}
$form_state->set('form_display', $display);
}
示例5: formElement
//.........这里部分代码省略.........
if ($item_mode == 'edit') {
if (isset($items[$delta]->entity) && ($default_edit_mode == 'preview' || $default_edit_mode == 'closed')) {
$links['collapse_button'] = array('#type' => 'submit', '#value' => t('Collapse'), '#name' => strtr($id_prefix, '-', '_') . '_collapse', '#weight' => 499, '#submit' => array(array(get_class($this), 'collapseItemSubmit')), '#limit_validation_errors' => array(array_merge($parents, array($field_name, 'add_more'))), '#delta' => $delta, '#ajax' => array('callback' => array(get_class($this), 'itemAjax'), 'wrapper' => $widget_state['ajax_wrapper_id'], 'effect' => 'fade'), '#access' => $paragraphs_entity->access('update'), '#prefix' => '<li class="collapse">', '#suffix' => '</li>');
}
// Hide the button when translating.
$button_access = $paragraphs_entity->access('delete') && $paragraphs_entity->language()->getId() == $paragraphs_entity->getUntranslated()->language()->getId();
$links['remove_button'] = array('#type' => 'submit', '#value' => t('Remove'), '#name' => strtr($id_prefix, '-', '_') . '_remove', '#weight' => 500, '#submit' => array(array(get_class($this), 'removeItemSubmit')), '#limit_validation_errors' => array(array_merge($parents, array($field_name, 'add_more'))), '#delta' => $delta, '#ajax' => array('callback' => array(get_class($this), 'itemAjax'), 'wrapper' => $widget_state['ajax_wrapper_id'], 'effect' => 'fade'), '#access' => $button_access, '#prefix' => '<li class="remove">', '#suffix' => '</li>');
$info['edit_button_info'] = array('#type' => 'markup', '#markup' => '<em>' . t('You are not allowed to edit this @title.', array('@title' => $this->getSetting('title'))) . '</em>', '#access' => !$paragraphs_entity->access('update') && $paragraphs_entity->access('delete'));
$info['remove_button_info'] = array('#type' => 'markup', '#markup' => '<em>' . t('You are not allowed to remove this @title.', array('@title' => $this->getSetting('title'))) . '</em>', '#access' => !$paragraphs_entity->access('delete') && $paragraphs_entity->access('update'));
$info['edit_remove_button_info'] = array('#type' => 'markup', '#markup' => '<em>' . t('You are not allowed to edit or remove this @title.', array('@title' => $this->getSetting('title'))) . '</em>', '#access' => !$paragraphs_entity->access('update') && !$paragraphs_entity->access('delete'));
} elseif ($item_mode == 'preview' || $item_mode == 'closed') {
$links['edit_button'] = array('#type' => 'submit', '#value' => t('Edit'), '#name' => strtr($id_prefix, '-', '_') . '_edit', '#weight' => 501, '#submit' => array(array(get_class($this), 'editItemSubmit')), '#limit_validation_errors' => array(array_merge($parents, array($field_name, 'add_more'))), '#delta' => $delta, '#ajax' => array('callback' => array(get_class($this), 'itemAjax'), 'wrapper' => $widget_state['ajax_wrapper_id'], 'effect' => 'fade'), '#access' => $paragraphs_entity->access('update'), '#prefix' => '<li class="edit">', '#suffix' => '</li>');
$links['remove_button'] = array('#type' => 'submit', '#value' => t('Remove'), '#name' => strtr($id_prefix, '-', '_') . '_remove', '#weight' => 502, '#submit' => array(array(get_class($this), 'removeItemSubmit')), '#limit_validation_errors' => array(array_merge($parents, array($field_name, 'add_more'))), '#delta' => $delta, '#ajax' => array('callback' => array(get_class($this), 'itemAjax'), 'wrapper' => $widget_state['ajax_wrapper_id'], 'effect' => 'fade'), '#access' => $paragraphs_entity->access('delete'), '#prefix' => '<li class="remove">', '#suffix' => '</li>');
if ($show_must_be_saved_warning) {
$info['must_be_saved_info'] = array('#type' => 'markup', '#markup' => '<em>' . t('Warning: this content must be saved to reflect changes on this @title item.', array('@title' => $this->getSetting('title'))) . '</em>');
}
$info['preview_info'] = array('#type' => 'markup', '#markup' => '<em>' . t('You are not allowed to view this @title.', array('@title' => $this->getSetting('title'))) . '</em>', '#access' => !$paragraphs_entity->access('view'));
$info['edit_button_info'] = array('#type' => 'markup', '#markup' => '<em>' . t('You are not allowed to edit this @title.', array('@title' => $this->getSetting('title'))) . '</em>', '#access' => !$paragraphs_entity->access('update') && $paragraphs_entity->access('delete'));
$info['remove_button_info'] = array('#type' => 'markup', '#markup' => '<em>' . t('You are not allowed to remove this @title.', array('@title' => $this->getSetting('title'))) . '</em>', '#access' => !$paragraphs_entity->access('delete') && $paragraphs_entity->access('update'));
$info['edit_remove_button_info'] = array('#type' => 'markup', '#markup' => '<em>' . t('You are not allowed to edit or remove this @title.', array('@title' => $this->getSetting('title'))) . '</em>', '#access' => !$paragraphs_entity->access('update') && !$paragraphs_entity->access('delete'));
} elseif ($item_mode == 'remove') {
$element['top']['paragraph_type_title']['info'] = array('#markup' => t('Deleted @title type: %type', array('@title' => $this->getSetting('title'), '%type' => $bundle_info['label'])));
$links['confirm_remove_button'] = array('#type' => 'submit', '#value' => t('Confirm removal'), '#name' => strtr($id_prefix, '-', '_') . '_confirm_remove', '#weight' => 503, '#submit' => array(array(get_class($this), 'confirmRemoveItemSubmit')), '#limit_validation_errors' => array(array_merge($parents, array($field_name, 'add_more'))), '#delta' => $delta, '#ajax' => array('callback' => array(get_class($this), 'itemAjax'), 'wrapper' => $widget_state['ajax_wrapper_id'], 'effect' => 'fade'), '#prefix' => '<li class="confirm-remove">', '#suffix' => '</li>');
$links['restore_button'] = array('#type' => 'submit', '#value' => t('Restore'), '#name' => strtr($id_prefix, '-', '_') . '_restore', '#weight' => 504, '#submit' => array(array(get_class($this), 'restoreItemSubmit')), '#limit_validation_errors' => array(array_merge($parents, array($field_name, 'add_more'))), '#delta' => $delta, '#ajax' => array('callback' => array(get_class($this), 'itemAjax'), 'wrapper' => $widget_state['ajax_wrapper_id'], 'effect' => 'fade'), '#prefix' => '<li class="restore">', '#suffix' => '</li>');
}
if (count($links)) {
$show_links = 0;
foreach ($links as $link_item) {
if (!isset($link_item['#access']) || $link_item['#access']) {
$show_links++;
}
}
if ($show_links > 0) {
$element['top']['links'] = $links;
if ($show_links > 1) {
$element['top']['links']['#theme_wrappers'] = array('dropbutton_wrapper', 'paragraphs_dropbutton_wrapper');
$element['top']['links']['prefix'] = array('#markup' => '<ul class="dropbutton">', '#weight' => -999);
$element['top']['links']['suffix'] = array('#markup' => '</li>', '#weight' => 999);
} else {
$element['top']['links']['#theme_wrappers'] = array('paragraphs_dropbutton_wrapper');
foreach ($links as $key => $link_item) {
unset($element['top']['links'][$key]['#prefix']);
unset($element['top']['links'][$key]['#suffix']);
}
}
$element['top']['links']['#weight'] = 1;
}
}
if (count($info)) {
$show_info = FALSE;
foreach ($info as $info_item) {
if (!isset($info_item['#access']) || $info_item['#access']) {
$show_info = TRUE;
break;
}
}
if ($show_info) {
$element['info'] = $info;
$element['info']['#weight'] = 998;
}
}
if (count($actions)) {
$show_actions = FALSE;
foreach ($actions as $action_item) {
if (!isset($action_item['#access']) || $action_item['#access']) {
$show_actions = TRUE;
break;
}
}
if ($show_actions) {
$element['actions'] = $actions;
$element['actions']['#type'] = 'actions';
$element['actions']['#weight'] = 999;
}
}
}
$display = EntityFormDisplay::collectRenderDisplay($paragraphs_entity, $this->getSetting('form_display_mode'));
if ($item_mode == 'edit') {
$display->buildForm($paragraphs_entity, $element['subform'], $form_state);
} elseif ($item_mode == 'preview') {
$element['subform'] = array();
$element['preview'] = entity_view($paragraphs_entity, 'preview', $paragraphs_entity->language()->getId());
$element['preview']['#access'] = $paragraphs_entity->access('view');
} elseif ($item_mode == 'closed') {
$element['subform'] = array();
} else {
$element['subform'] = array();
}
$element['subform']['#attributes']['class'][] = 'paragraphs-subform';
$element['subform']['#access'] = $paragraphs_entity->access('update');
if ($item_mode == 'removed') {
$element['#access'] = FALSE;
}
$widget_state['paragraphs'][$delta] = array('entity' => $paragraphs_entity, 'display' => $display, 'mode' => $item_mode);
static::setWidgetState($parents, $field_name, $form_state, $widget_state);
} else {
$element['#access'] = FALSE;
}
return $element;
}
示例6: getFormDisplay
/**
* Gets the form display for the given entity.
*
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* The entity.
* @param string $form_mode
* The form mode.
*
* @return \Drupal\Core\Entity\Display\EntityFormDisplayInterface
* The form display.
*/
protected function getFormDisplay(ContentEntityInterface $entity, $form_mode)
{
return EntityFormDisplay::collectRenderDisplay($entity, $form_mode);
}
示例7: getEntityFormDisplay
/**
* Gets the entity form display.
*
* @param mixed[] $element
* @param \Drupal\Core\Form\FormStateInterface $form_state
*
* @return \Drupal\Core\Entity\Display\EntityFormDisplayInterface
*/
protected function getEntityFormDisplay(array $element, FormStateInterface $form_state)
{
$key = 'payment_reference.element.payment_reference.entity_form_display.' . $element['#name'];
if (!$form_state->has($key)) {
$entity_form_display = EntityFormDisplay::collectRenderDisplay($this->getPayment($element, $form_state), 'payment_reference');
$form_state->set($key, $entity_form_display);
}
return $form_state->get($key);
}
示例8: formElement
//.........这里部分代码省略.........
$info['remove_button_info'] = array('#type' => 'markup', '#markup' => '<em>' . $this->t('You are not allowed to remove this @title.', array('@title' => $this->getSetting('title'))) . '</em>', '#access' => !$paragraphs_entity->access('delete') && $paragraphs_entity->access('update'));
$info['edit_remove_button_info'] = array('#type' => 'markup', '#markup' => '<em>' . $this->t('You are not allowed to edit or remove this @title.', array('@title' => $this->getSetting('title'))) . '</em>', '#access' => !$paragraphs_entity->access('update') && !$paragraphs_entity->access('delete'));
} elseif ($item_mode == 'preview' || $item_mode == 'closed') {
$links['edit_button'] = array('#type' => 'submit', '#value' => $this->t('Edit'), '#name' => strtr($id_prefix, '-', '_') . '_edit', '#weight' => 501, '#submit' => array(array(get_class($this), 'paragraphsItemSubmit')), '#limit_validation_errors' => array(array_merge($parents, array($field_name, 'add_more'))), '#delta' => $delta, '#ajax' => array('callback' => array(get_class($this), 'itemAjax'), 'wrapper' => $widget_state['ajax_wrapper_id'], 'effect' => 'fade'), '#access' => $paragraphs_entity->access('update'), '#prefix' => '<li class="edit">', '#suffix' => '</li>', '#paragraphs_mode' => 'edit');
$links['remove_button'] = array('#type' => 'submit', '#value' => $this->t('Remove'), '#name' => strtr($id_prefix, '-', '_') . '_remove', '#weight' => 502, '#submit' => array(array(get_class($this), 'paragraphsItemSubmit')), '#limit_validation_errors' => array(array_merge($parents, array($field_name, 'add_more'))), '#delta' => $delta, '#ajax' => array('callback' => array(get_class($this), 'itemAjax'), 'wrapper' => $widget_state['ajax_wrapper_id'], 'effect' => 'fade'), '#access' => $paragraphs_entity->access('delete'), '#prefix' => '<li class="remove">', '#suffix' => '</li>', '#paragraphs_mode' => 'remove');
if ($show_must_be_saved_warning) {
$info['must_be_saved_info'] = array('#type' => 'markup', '#markup' => '<em>' . $this->t('Warning: this content must be saved to reflect changes on this @title item.', array('@title' => $this->getSetting('title'))) . '</em>');
}
$info['preview_info'] = array('#type' => 'markup', '#markup' => '<em>' . $this->t('You are not allowed to view this @title.', array('@title' => $this->getSetting('title'))) . '</em>', '#access' => !$paragraphs_entity->access('view'));
$info['edit_button_info'] = array('#type' => 'markup', '#markup' => '<em>' . $this->t('You are not allowed to edit this @title.', array('@title' => $this->getSetting('title'))) . '</em>', '#access' => !$paragraphs_entity->access('update') && $paragraphs_entity->access('delete'));
$info['remove_button_info'] = array('#type' => 'markup', '#markup' => '<em>' . $this->t('You are not allowed to remove this @title.', array('@title' => $this->getSetting('title'))) . '</em>', '#access' => !$paragraphs_entity->access('delete') && $paragraphs_entity->access('update'));
$info['edit_remove_button_info'] = array('#type' => 'markup', '#markup' => '<em>' . $this->t('You are not allowed to edit or remove this @title.', array('@title' => $this->getSetting('title'))) . '</em>', '#access' => !$paragraphs_entity->access('update') && !$paragraphs_entity->access('delete'));
} elseif ($item_mode == 'remove') {
$element['top']['paragraph_type_title']['info'] = array('#markup' => $this->t('Deleted @title: %type', ['@title' => $this->getSetting('title'), '%type' => $bundle_info['label']]));
$links['confirm_remove_button'] = array('#type' => 'submit', '#value' => $this->t('Confirm removal'), '#name' => strtr($id_prefix, '-', '_') . '_confirm_remove', '#weight' => 503, '#submit' => array(array(get_class($this), 'paragraphsItemSubmit')), '#limit_validation_errors' => array(array_merge($parents, array($field_name, 'add_more'))), '#delta' => $delta, '#ajax' => array('callback' => array(get_class($this), 'itemAjax'), 'wrapper' => $widget_state['ajax_wrapper_id'], 'effect' => 'fade'), '#prefix' => '<li class="confirm-remove">', '#suffix' => '</li>', '#paragraphs_mode' => 'removed');
$links['restore_button'] = array('#type' => 'submit', '#value' => $this->t('Restore'), '#name' => strtr($id_prefix, '-', '_') . '_restore', '#weight' => 504, '#submit' => array(array(get_class($this), 'paragraphsItemSubmit')), '#limit_validation_errors' => array(array_merge($parents, array($field_name, 'add_more'))), '#delta' => $delta, '#ajax' => array('callback' => array(get_class($this), 'itemAjax'), 'wrapper' => $widget_state['ajax_wrapper_id'], 'effect' => 'fade'), '#prefix' => '<li class="restore">', '#suffix' => '</li>', '#paragraphs_mode' => 'edit');
}
if (count($links)) {
$show_links = 0;
foreach ($links as $link_item) {
if (!isset($link_item['#access']) || $link_item['#access']) {
$show_links++;
}
}
if ($show_links > 0) {
$element['top']['links'] = $links;
if ($show_links > 1) {
$element['top']['links']['#theme_wrappers'] = array('dropbutton_wrapper', 'paragraphs_dropbutton_wrapper');
$element['top']['links']['prefix'] = array('#markup' => '<ul class="dropbutton">', '#weight' => -999);
$element['top']['links']['suffix'] = array('#markup' => '</li>', '#weight' => 999);
} else {
$element['top']['links']['#theme_wrappers'] = array('paragraphs_dropbutton_wrapper');
foreach ($links as $key => $link_item) {
unset($element['top']['links'][$key]['#prefix']);
unset($element['top']['links'][$key]['#suffix']);
}
}
$element['top']['links']['#weight'] = 1;
}
}
if (count($info)) {
$show_info = FALSE;
foreach ($info as $info_item) {
if (!isset($info_item['#access']) || $info_item['#access']) {
$show_info = TRUE;
break;
}
}
if ($show_info) {
$element['info'] = $info;
$element['info']['#weight'] = 998;
}
}
if (count($actions)) {
$show_actions = FALSE;
foreach ($actions as $action_item) {
if (!isset($action_item['#access']) || $action_item['#access']) {
$show_actions = TRUE;
break;
}
}
if ($show_actions) {
$element['actions'] = $actions;
$element['actions']['#type'] = 'actions';
$element['actions']['#weight'] = 999;
}
}
}
$display = EntityFormDisplay::collectRenderDisplay($paragraphs_entity, $this->getSetting('form_display_mode'));
if ($item_mode == 'edit') {
$display->buildForm($paragraphs_entity, $element['subform'], $form_state);
foreach (Element::children($element['subform']) as $field) {
if ($paragraphs_entity->hasField($field)) {
$translatable = $paragraphs_entity->{$field}->getFieldDefinition()->isTranslatable();
if ($translatable) {
$element['subform'][$field]['widget']['#after_build'][] = [static::class, 'removeTranslatabilityClue'];
}
}
}
} elseif ($item_mode == 'preview') {
$element['subform'] = array();
$element['preview'] = entity_view($paragraphs_entity, 'preview', $paragraphs_entity->language()->getId());
$element['preview']['#access'] = $paragraphs_entity->access('view');
} elseif ($item_mode == 'closed') {
$element['subform'] = array();
} else {
$element['subform'] = array();
}
$element['subform']['#attributes']['class'][] = 'paragraphs-subform';
$element['subform']['#access'] = $paragraphs_entity->access('update');
if ($item_mode == 'removed') {
$element['#access'] = FALSE;
}
$widget_state['paragraphs'][$delta] = array('entity' => $paragraphs_entity, 'display' => $display, 'mode' => $item_mode);
static::setWidgetState($parents, $field_name, $form_state, $widget_state);
} else {
$element['#access'] = FALSE;
}
return $element;
}