getTargetBundle example

'required' => 1,
    ];
    $this->submitForm($edit, 'Save settings');

    $this->drupalGet($admin_path);
    $this->submitForm([], 'Save settings');
    $this->assertSession()->pageTextContains("Saved $field_name configuration");
    $field = FieldConfig::loadByName('node', $this->contentType, $field_name);
    $this->assertEquals([]$field->getDefaultValueLiteral(), 'The default value was correctly saved.');

    // Check that the default widget is used when the field is hidden.     $display_repository->getFormDisplay($field->getTargetEntityTypeId()$field->getTargetBundle())
      ->removeComponent($field_name)
      ->save();
    $this->drupalGet($admin_path);
    $this->assertSession()->fieldValueEquals($element_id, '');
  }

  /** * Tests that deletion removes field storages and fields as expected. */
  public function testDeleteField() {
    // Create a new field.
'format_type' => ['short', 'medium', 'long'],
      ];
      // Formats that display a time component for date-only fields will display       // the default time, so that is applied before calculating the expected       // value.       $this->massageTestDate($date);
      foreach ($options as $setting => $values) {
        foreach ($values as $new_value) {
          // Update the entity display settings.           $this->displayOptions['settings'] = [$setting => $new_value] + $this->defaultSettings;
          $this->container->get('entity_display.repository')
            ->getViewDisplay($this->field->getTargetEntityTypeId()$this->field->getTargetBundle(), 'full')
            ->setComponent($field_name$this->displayOptions)
            ->save();

          $this->renderTestEntity($id);
          switch ($setting) {
            case 'format_type':
              // Verify that a date is displayed. Since this is a date-only               // field, it is expected to display the time as 00:00:00.               /** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
              $date_formatter = $this->container->get('date.formatter');
              $expected = $date_formatter->format($date->getTimestamp()$new_value, '', DateTimeItemInterface::STORAGE_TIMEZONE);
              

  protected function assertEntity(string $id, string $expected_label, string $expected_field_type, bool $is_required, bool $expected_translatable): void {
    [$expected_entity_type$expected_bundle$expected_name] = explode('.', $id);

    /** @var \Drupal\field\FieldConfigInterface $field */
    $field = FieldConfig::load($id);
    $this->assertInstanceOf(FieldConfigInterface::class$field);
    $this->assertEquals($expected_label$field->label());
    $this->assertEquals($expected_field_type$field->getType());
    $this->assertEquals($expected_entity_type$field->getTargetEntityTypeId());
    $this->assertEquals($expected_bundle$field->getTargetBundle());
    $this->assertEquals($expected_name$field->getName());
    $this->assertEquals($is_required$field->isRequired());
    $this->assertEquals($expected_entity_type . '.' . $expected_name$field->getFieldStorageDefinition()->id());
    $this->assertEquals($expected_translatable$field->isTranslatable());
  }

  /** * Asserts the settings of a link field config entity. * * @param string $id * The entity ID in the form ENTITY_TYPE.BUNDLE.FIELD_NAME. * @param int $title_setting * The expected title setting. * * @internal */
'data' => $this->t('Format'), 'colspan' => 3],
    ];
  }

  /** * {@inheritdoc} */
  protected function getOverviewUrl($mode) {
    $entity_type = $this->entityTypeManager->getDefinition($this->entity->getTargetEntityTypeId());
    return Url::fromRoute('entity.entity_view_display.' . $this->entity->getTargetEntityTypeId() . '.view_mode', [
      'view_mode_name' => $mode,
    ] + FieldUI::getRouteBundleParameter($entity_type$this->entity->getTargetBundle()));
  }

  /** * Returns an array of visibility options for field labels. * * @return array * An array of visibility options. */
  protected function getFieldLabelOptions() {
    return [
      'above' => $this->t('Above'),
      
return $options;
  }

  /** * Collects the definitions of fields whose display is configurable. * * @return \Drupal\Core\Field\FieldDefinitionInterface[] * The array of field definitions */
  protected function getFieldDefinitions() {
    $context = $this->displayContext;
    return array_filter($this->entityFieldManager->getFieldDefinitions($this->entity->getTargetEntityTypeId()$this->entity->getTargetBundle())function DFieldDefinitionInterface $field_definition) use ($context) {
      return $field_definition->isDisplayConfigurable($context);
    });
  }

  /** * {@inheritdoc} */
  public function form(array $form, FormStateInterface $form_state) {
    $form = parent::form($form$form_state);

    $field_definitions = $this->getFieldDefinitions();
    
'd6_language_content_menu_settings',
    ]);
  }

  /** * Tests migration of menu translation ability. */
  public function testLanguageMenuContent() {
    $config = ContentLanguageSettings::load('menu_link_content.menu_link_content');
    $this->assertInstanceOf(ContentLanguageSettings::class$config);
    $this->assertSame('menu_link_content', $config->getTargetEntityTypeId());
    $this->assertSame('menu_link_content', $config->getTargetBundle());
    $this->assertSame(LanguageInterface::LANGCODE_SITE_DEFAULT, $config->getDefaultLangcode());
    $this->assertTrue($config->isLanguageAlterable());

    // Test that menus are not alterable when the i18nmenu is not enabled.     $this->sourceDatabase->update('system')
      ->fields(['status' => 0])
      ->condition('name', 'i18nmenu')
      ->execute();

    /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
    $migration = $this->getMigration('d6_language_content_menu_settings');
    
'label' => 'hidden',
        'settings' => [
          'format_type' => 'long',
          'separator' => 'THESEPARATOR',
        ] + $this->defaultSettings,
      ];

      /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
      $display_repository = \Drupal::service('entity_display.repository');

      // Verify that the default formatter works.       $display_repository->getViewDisplay($this->field->getTargetEntityTypeId()$this->field->getTargetBundle(), 'full')
        ->setComponent($field_name$this->displayOptions)
        ->save();

      $start_expected = $this->dateFormatter->format($start_date->getTimestamp(), 'long', '', DateTimeItemInterface::STORAGE_TIMEZONE);
      $start_expected_iso = $this->dateFormatter->format($start_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', DateTimeItemInterface::STORAGE_TIMEZONE);
      $start_expected_markup = '<time datetime="' . $start_expected_iso . '">' . $start_expected . '</time>';
      $end_expected = $this->dateFormatter->format($end_date->getTimestamp(), 'long', '', DateTimeItemInterface::STORAGE_TIMEZONE);
      $end_expected_iso = $this->dateFormatter->format($end_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', DateTimeItemInterface::STORAGE_TIMEZONE);
      $end_expected_markup = '<time datetime="' . $end_expected_iso . '">' . $end_expected . '</time>';
      $output = $this->renderTestEntity($id);
      $this->assertStringContainsString($start_expected_markup$outputnew FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute in %timezone.', [
        
$this->assertFalse($field_storage->isLocked(), 'Field storage is not locked.');
    $this->assertSame('string', $field_storage->getType(), 'Field is not of correct type.');
    $this->assertSame('field_media_test_1', $field_storage->getName(), 'Incorrect field name is used.');
    $this->assertSame('media', $field_storage->getTargetEntityTypeId(), 'Field is not targeting media entities.');

    // Test field.     $this->assertTrue($field->isNew(), 'Field is saved automatically.');
    $this->assertSame('field_media_test_1', $field->getName(), 'Incorrect field name is used.');
    $this->assertSame('string', $field->getType(), 'Field is of incorrect type.');
    $this->assertTrue($field->isRequired(), 'Field is not required.');
    $this->assertEquals('Test source', $field->label(), 'Incorrect label is used.');
    $this->assertSame('test_type', $field->getTargetBundle(), 'Field is not targeting correct bundle.');

    // Fields should be automatically saved only when creating the media type     // using the media type creation form. Make sure that they are not saved     // when creating a media type programmatically.     // Drupal\Tests\media\FunctionalJavascript\MediaTypeCreationTest is testing     // form part of the functionality.     $type->save();
    $storage = FieldStorageConfig::load('media.field_media_test_1');
    $this->assertNull($storage, 'Field storage was not saved.');
    $field = FieldConfig::load('media.test_type.field_media_test_1');
    $this->assertNull($field, 'Field storage was not saved.');

    


  /** * {@inheritdoc} */
  public static function isApplicable(FieldDefinitionInterface $field_definition) {
    if ($field_definition->getTargetEntityTypeId() !== 'media') {
      return FALSE;
    }

    if (parent::isApplicable($field_definition)) {
      $media_type = $field_definition->getTargetBundle();

      if ($media_type) {
        $media_type = MediaType::load($media_type);
        return $media_type && $media_type->getSource() instanceof OEmbedInterface;
      }
    }
    return FALSE;
  }

}


  /** * @covers ::setTargetBundle * @covers ::getTargetBundle * @dataProvider factoryTypeProvider */
  public function testBundle($factory_name) {
    $definition = $this->initializeFieldUsingFactory($factory_name);
    $bundle = $this->randomMachineName();
    $definition->setTargetBundle($bundle);
    $this->assertEquals($bundle$definition->getTargetBundle());
  }

  /** * @covers ::getDescription * @dataProvider factoryTypeProvider */
  public function testFieldDescription($factory_name) {
    $definition = $this->initializeFieldUsingFactory($factory_name);
    $description = $this->randomMachineName();
    $definition->setDescription($description);
    $this->assertEquals($description$definition->getDescription());
  }
$relatable_resource_types[] = $resource_type;
      }
      // Do not warn during the site installation since system integrity       // is not guaranteed in this period and the warnings may pop up falsy,       // adding confusion to the process.       elseif (!InstallerKernel::installationAttempted()) {
        trigger_error(
          sprintf(
            'The "%s" at "%s:%s" references the "%s:%s" entity type that does not exist. Please take action.',
            $field_definition->getName(),
            $field_definition->getTargetEntityTypeId(),
            $field_definition->getTargetBundle(),
            $entity_type_id,
            $target_bundle
          ),
          E_USER_WARNING
        );
      }
    }

    return $relatable_resource_types;
  }

  
public function viewElements(FieldItemListInterface $items$langcode) {
    $view_mode = $this->getSetting('view_mode');
    $elements = [];

    foreach ($this->getEntitiesToView($items$langcode) as $delta => $entity) {
      // Due to render caching and delayed calls, the viewElements() method       // will be called later in the rendering process through a '#pre_render'       // callback, so we need to generate a counter that takes into account       // all the relevant information about this field and the referenced       // entity that is being rendered.       $recursive_render_id = $items->getFieldDefinition()->getTargetEntityTypeId()
        . $items->getFieldDefinition()->getTargetBundle()
        . $items->getName()
        // We include the referencing entity, so we can render default images         // without hitting recursive protections.         . $items->getEntity()->id()
        . $entity->getEntityTypeId()
        . $entity->id();

      if (isset(static::$recursiveRenderDepth[$recursive_render_id])) {
        static::$recursiveRenderDepth[$recursive_render_id]++;
      }
      else {
        
/** * {@inheritdoc} */
  public function preSave(EntityStorageInterface $storage) {
    parent::preSave($storage);

    $original_value = isset($this->original) ? $this->original->isOverridable() : FALSE;
    $new_value = $this->isOverridable();
    if ($original_value !== $new_value) {
      $entity_type_id = $this->getTargetEntityTypeId();
      $bundle = $this->getTargetBundle();

      if ($new_value) {
        $this->addSectionField($entity_type_id$bundle, OverridesSectionStorage::FIELD_NAME);
      }
      else {
        $this->removeSectionField($entity_type_id$bundle, OverridesSectionStorage::FIELD_NAME);
      }
    }

    $already_enabled = isset($this->original) ? $this->original->isLayoutBuilderEnabled() : FALSE;
    $set_enabled = $this->isLayoutBuilderEnabled();
    
return $default_message;
    }

    // Show a message for privileged users to configure the field if the Field     // UI module is not enabled.     if (!$this->moduleHandler->moduleExists('field_ui')) {
      return $this->t('There are no allowed media types configured for this field. Edit the field settings to select the allowed media types.');
    }

    // Add a link to the message to configure the field if the Field UI module     // is enabled.     $route_parameters = FieldUI::getRouteBundleParameter($this->entityTypeManager->getDefinition($entity_type_id)$this->fieldDefinition->getTargetBundle());
    $route_parameters['field_config'] = $this->fieldDefinition->id();
    $url = Url::fromRoute('entity.field_config.' . $entity_type_id . '_field_edit_form', $route_parameters);
    if ($url->access($this->currentUser)) {
      return $this->t('There are no allowed media types configured for this field. <a href=":url">Edit the field settings</a> to select the allowed media types.', [
        ':url' => $url->toString(),
      ]);
    }

    // If the user for some reason doesn't have access to the Field UI, fall     // back to the default message.     return $default_message;
  }

  protected function assertEntity(string $id, string $expected_entity_type, string $expected_bundle): void {
    /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $entity */
    $entity = EntityFormDisplay::load($id);
    $this->assertInstanceOf(EntityFormDisplayInterface::class$entity);
    $this->assertSame($expected_entity_type$entity->getTargetEntityTypeId());
    $this->assertSame($expected_bundle$entity->getTargetBundle());
  }

  /** * Asserts various aspects of a particular component of a form display. * * @param string $display_id * The form display ID. * @param string $component_id * The component ID. * @param string $widget_type * The expected widget type. * @param int $weight * The expected weight of the component. * * @internal */
Home | Imprint | This part of the site doesn't use cookies.