当前位置: 首页>>代码示例>>PHP>>正文


PHP FieldItemListInterface::getParent方法代码示例

本文整理汇总了PHP中Drupal\Core\Field\FieldItemListInterface::getParent方法的典型用法代码示例。如果您正苦于以下问题:PHP FieldItemListInterface::getParent方法的具体用法?PHP FieldItemListInterface::getParent怎么用?PHP FieldItemListInterface::getParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Field\FieldItemListInterface的用法示例。


在下文中一共展示了FieldItemListInterface::getParent方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: formElement

  /**
   * {@inheritdoc}
   */
  public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
    if (!$this->canBuildForm($form_state)) {
      return $element;
    }

    $element['#type'] = 'fieldset';
    $this->setIefId(sha1($items->getName() . '-ief-single-' . $delta));
    $entity = NULL;
    if ($items->get($delta)->target_id) {
      $entity = $items->get($delta)->entity;
      if (!$entity) {
        $element['warning']['#markup'] = t('Unable to load the referenced entity.');
        return $element;
      }
    }

    $op = isset($entity) ? 'edit' : 'add';
    $language = $items->getParent()->getValue()->language()->getId();
    $parents = array_merge($element['#field_parents'], [
      $items->getName(),
      $delta,
      'inline_entity_form'
    ]);
    $bundle = reset($this->getFieldSetting('handler_settings')['target_bundles']);
    $element['inline_entity_form'] = $this->getInlineEntityForm($op, $language, $delta, $parents, $bundle, $entity, TRUE);

    return $element;
  }
开发者ID:housineali,项目名称:drpl8_dv,代码行数:31,代码来源:InlineEntityFormSimple.php

示例2: formElement

 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     // Trick inline_entity_form_form_alter() into attaching the handlers,
     // WidgetSubmit will be needed once extractFormValues fills the $form_state.
     $parents = array_merge($element['#field_parents'], [$items->getName()]);
     $ief_id = sha1(implode('-', $parents));
     $form_state->set(['inline_entity_form', $ief_id], []);
     $element['#type'] = 'fieldset';
     $item = $items->get($delta);
     if ($item->target_id && !$item->entity) {
         $element['warning']['#markup'] = $this->t('Unable to load the referenced entity.');
         return $element;
     }
     $entity = $item->entity;
     $op = $entity ? 'edit' : 'add';
     $language = $items->getParent()->getValue()->language()->getId();
     $parents = array_merge($element['#field_parents'], [$items->getName(), $delta, 'inline_entity_form']);
     $bundle = reset($this->getFieldSetting('handler_settings')['target_bundles']);
     $element['inline_entity_form'] = $this->getInlineEntityForm($op, $bundle, $language, $delta, $parents, $entity);
     if ($op == 'edit') {
         /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
         if (!$entity->access('update')) {
             // The user isn't allowed to edit the entity, but still needs to see
             // it, to be able to reorder values.
             $element['entity_label'] = ['#type' => 'markup', '#markup' => $entity->label()];
             // Hide the inline form. getInlineEntityForm() still needed to be
             // called because otherwise the field re-ordering doesn't work.
             $element['inline_entity_form']['#access'] = FALSE;
         }
     }
     return $element;
 }
开发者ID:CIGIHub,项目名称:bsia-drupal8,代码行数:35,代码来源:InlineEntityFormSimple.php

示例3: formElement

 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     if (!$this->canBuildForm($form_state)) {
         return $element;
     }
     $this->setIefId(sha1($items->getName() . '-ief-single-' . $delta));
     $entity_type = $this->getFieldSettings()['target_type'];
     $element['#type'] = 'fieldset';
     if ($items->get($delta)->target_id) {
         $entity = $this->entityManager->getStorage($entity_type)->load($items->get($delta)->target_id);
         if ($entity) {
             $element['inline_entity_form'] = $this->getInlineEntityForm('edit', $entity_type, $items->getParent()->getValue()->language()->getId(), $delta, array_merge($element['#field_parents'], [$items->getName(), $delta, 'inline_entity_form']), reset($this->getFieldSettings()['handler_settings']['target_bundles']), $entity, TRUE);
         } else {
             $element['warning']['#markup'] = t('Unable to load referenced entity.');
         }
     } else {
         $element['inline_entity_form'] = $this->getInlineEntityForm('add', $entity_type, $items->getParent()->getValue()->language()->getId(), $delta, array_merge($element['#field_parents'], [$items->getName(), $delta, 'inline_entity_form']), reset($this->getFieldSettings()['handler_settings']['target_bundles']), NULL, TRUE);
     }
     return $element;
 }
开发者ID:atif-shaikh,项目名称:DCX-Profile,代码行数:23,代码来源:InlineEntityFormSimple.php

示例4: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode = NULL)
 {
     $output = [];
     $attributes = new Attribute();
     if ($this->getSetting('tag') == 'h1') {
         $attributes->addClass('title');
         $attributes->addClass('replaced-title');
         $attributes->setAttribute('id', 'page-title');
     }
     $parent = $items->getParent()->getValue();
     foreach ($items as $item) {
         $text = $item->getValue()['value'];
         if ($this->getSetting('linked')) {
             $text = $this->l($text, $parent->urlInfo());
         }
         $output[] = $build['string'] = ['#type' => 'inline_template', '#template' => '<{{ tag }} {{ attributes }}>{{ text }}</{{ tag }}>', '#context' => ['text' => $text, 'tag' => $this->getSetting('tag'), 'attributes' => (string) $attributes]];
     }
     return $output;
 }
开发者ID:lokeoke,项目名称:d8intranet,代码行数:22,代码来源:LinkedAndWrapped.php

示例5: formElement

 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     if (!$this->canBuildForm($form_state)) {
         return $element;
     }
     $settings = $this->getSettings();
     $target_type = $this->getFieldSetting('target_type');
     // Get the entity type labels for the UI strings.
     $labels = $this->labels();
     // Build a parents array for this element's values in the form.
     $parents = array_merge($element['#field_parents'], array($items->getName(), 'form'));
     // Assign a unique identifier to each IEF widget.
     // Since $parents can get quite long, sha1() ensures that every id has
     // a consistent and relatively short length while maintaining uniqueness.
     $this->setIefId(sha1(implode('-', $parents)));
     // Get the langcode of the parent entity.
     $parent_langcode = $items->getParent()->getValue()->language()->getId();
     // Determine the wrapper ID for the entire element.
     $wrapper = 'inline-entity-form-' . $this->getIefId();
     $element = array('#type' => 'fieldset', '#tree' => TRUE, '#description' => NULL, '#prefix' => '<div id="' . $wrapper . '">', '#suffix' => '</div>', '#ief_id' => $this->getIefId(), '#ief_root' => TRUE) + $element;
     $element['#attached']['library'][] = 'inline_entity_form/widget';
     // Initialize the IEF array in form state.
     if (!$form_state->has(['inline_entity_form', $this->getIefId(), 'settings'])) {
         $form_state->set(['inline_entity_form', $this->getIefId(), 'settings'], $this->getFieldSettings());
     }
     if (!$form_state->has(['inline_entity_form', $this->getIefId(), 'instance'])) {
         $form_state->set(['inline_entity_form', $this->getIefId(), 'instance'], $this->fieldDefinition);
     }
     if (!$form_state->has(['inline_entity_form', $this->getIefId(), 'form'])) {
         $form_state->set(['inline_entity_form', $this->getIefId(), 'form'], NULL);
     }
     if (!$form_state->has(['inline_entity_form', $this->getIefId(), 'array_parents'])) {
         $form_state->set(['inline_entity_form', $this->getIefId(), 'array_parents'], $parents);
     }
     $entities = $form_state->get(['inline_entity_form', $this->getIefId(), 'entities']);
     if (!isset($entities)) {
         // Load the entities from the $items array and store them in the form
         // state for further manipulation.
         $form_state->set(['inline_entity_form', $this->getIefId(), 'entities'], array());
         if (count($items)) {
             foreach ($items as $delta => $item) {
                 if ($item->entity && is_object($item->entity)) {
                     $form_state->set(['inline_entity_form', $this->getIefId(), 'entities', $delta], array('entity' => $item->entity, '_weight' => $delta, 'form' => NULL, 'needs_save' => FALSE));
                 }
             }
         }
         $entities = $form_state->get(['inline_entity_form', $this->getIefId(), 'entities']);
     }
     // Remove any leftover data from removed entity references.
     foreach ($entities as $key => $value) {
         if (!isset($value) || !isset($value['entity'])) {
             unset($entities[$key]);
         }
     }
     // Build the "Multiple value" widget.
     // TODO - does this belong in #element_validate?
     $element['#element_validate'] = [[get_class($this), 'updateRowWeights']];
     // Add the required element marker & validation.
     if ($element['#required']) {
         $element['#element_validate'][] = [get_class($this), 'requiredField'];
     }
     $element['entities'] = array('#tree' => TRUE, '#theme' => 'inline_entity_form_entity_table', '#entity_type' => $target_type);
     // Get the fields that should be displayed in the table.
     $target_bundles = $this->getTargetBundles();
     $fields = $this->iefHandler->tableFields($target_bundles);
     $context = array('parent_entity_type' => $this->fieldDefinition->getTargetEntityTypeId(), 'parent_bundle' => $this->fieldDefinition->getTargetBundle(), 'field_name' => $this->fieldDefinition->getName(), 'entity_type' => $target_type, 'allowed_bundles' => $target_bundles);
     $this->moduleHandler->alter('inline_entity_form_table_fields', $fields, $context);
     $element['entities']['#table_fields'] = $fields;
     $weight_delta = max(ceil(count($entities) * 1.2), 50);
     foreach ($entities as $key => $value) {
         // Data used by theme_inline_entity_form_entity_table().
         /** @var \Drupal\Core\Entity\EntityInterface $entity */
         $entity = $value['entity'];
         $element['entities'][$key]['#entity'] = $value['entity'];
         $element['entities'][$key]['#needs_save'] = $value['needs_save'];
         // Handle row weights.
         $element['entities'][$key]['#weight'] = $value['_weight'];
         // First check to see if this entity should be displayed as a form.
         if (!empty($value['form'])) {
             $element['entities'][$key]['title'] = array();
             $element['entities'][$key]['delta'] = array('#type' => 'value', '#value' => $value['_weight']);
             // Add the appropriate form.
             if ($value['form'] == 'edit') {
                 $element['entities'][$key]['form'] = ['#type' => 'container', '#attributes' => ['class' => ['ief-form', 'ief-form-row']], 'inline_entity_form' => $this->getInlineEntityForm($value['form'], $parent_langcode, $key, array_merge($parents, ['inline_entity_form', 'entities', $key, 'form']), $entity->bundle(), $entity)];
                 $element['entities'][$key]['form']['inline_entity_form']['#process'] = [['\\Drupal\\inline_entity_form\\Element\\InlineEntityForm', 'processEntityForm'], [get_class($this), 'addIefSubmitCallbacks'], [get_class($this), 'buildEntityFormActions']];
             } elseif ($value['form'] == 'remove') {
                 $element['entities'][$key]['form'] = ['#type' => 'container', '#attributes' => ['class' => ['ief-form', 'ief-form-row']], '#parents' => array_merge($parents, ['entities', $key, 'form']), '#entity' => $entity, '#ief_id' => $this->getIefId(), '#ief_row_delta' => $key];
                 $this->buildRemoveForm($element['entities'][$key]['form']);
             }
         } else {
             $row =& $element['entities'][$key];
             $row['title'] = array();
             $row['delta'] = array('#type' => 'weight', '#delta' => $weight_delta, '#default_value' => $value['_weight'], '#attributes' => array('class' => array('ief-entity-delta')));
             // Add an actions container with edit and delete buttons for the entity.
             $row['actions'] = array('#type' => 'container', '#attributes' => array('class' => array('ief-entity-operations')));
             // Make sure entity_access is not checked for unsaved entities.
             $entity_id = $entity->id();
//.........这里部分代码省略.........
开发者ID:tedbow,项目名称:scheduled-updates-demo,代码行数:101,代码来源:InlineEntityFormComplex.php


注:本文中的Drupal\Core\Field\FieldItemListInterface::getParent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。