コード例 #1
0
 /**
  * Setup entity reference field for this update type on add.
  *
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  */
 protected function setUpFieldReferences(FormStateInterface $form_state)
 {
     $reference_settings = $form_state->getValue('reference_settings');
     if ($reference_settings['new_field']['create']) {
         $new_field_settings = $reference_settings['new_field'];
         $new_field_settings += $reference_settings['new_field']['cardinality_container'];
         unset($new_field_settings['cardinality_container']);
         $this->fieldManager->createNewReferenceField($new_field_settings, $this->entity);
     }
     if (!empty($reference_settings['existing_fields']['update'])) {
         $existing_field_settings = $reference_settings['existing_fields'];
         $this->fieldManager->updateExistingReferenceFields($existing_field_settings, $this->entity);
     }
 }
コード例 #2
0
  /**
   * Setup entity reference field for this update type on add.
   *
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   */
  protected function setUpFieldReferences(FormStateInterface $form_state) {
    $reference_settings = $form_state->getValue('reference_settings');
    $bundles = array_filter($reference_settings['bundles']);
    $field_use = $reference_settings['reference_field_options'];
    if ($field_use == 'new') {
      $new_field_settings = $reference_settings['new_field'];
      $new_field_settings += $reference_settings['new_field']['cardinality_container'];
      unset($new_field_settings['cardinality_container']);
      $new_field_settings['bundles'] = $bundles;
      $this->fieldManager->createNewReferenceField($new_field_settings, $this->entity);
    }
    elseif ($field_use == 'reuse') {
      $existing_field_settings['field_id'] = $reference_settings['existing_field'];
      $existing_field_settings['bundles'] = $bundles;
      $this->fieldManager->updateExistingReferenceFields($existing_field_settings, $this->entity);

    }
  }