loadEntityByConfigTarget example

if (!$media) {
        $this->loggerFactory->get('media')->error('During rendering of embedded media: the media item with UUID "@uuid" does not exist.', ['@uuid' => $uuid]);
      }
      else {
        $media = $this->entityRepository->getTranslationFromContext($media$langcode);
        $media = clone $media;
        $this->applyPerEmbedMediaOverrides($node$media);
      }

      $view_mode = NULL;
      if ($view_mode_id !== EntityDisplayRepositoryInterface::DEFAULT_DISPLAY_MODE) {
        $view_mode = $this->entityRepository->loadEntityByConfigTarget('entity_view_mode', "media.$view_mode_id");
        if (!$view_mode) {
          $this->loggerFactory->get('media')->error('During rendering of embedded media: the view mode "@view-mode-id" does not exist.', ['@view-mode-id' => $view_mode_id]);
        }
      }

      $build = $media && ($view_mode || $view_mode_id === EntityDisplayRepositoryInterface::DEFAULT_DISPLAY_MODE)
        ? $this->renderMedia($media$view_mode_id$langcode)
        : $this->renderMissingMediaIndicator();

      if (empty($build['#attributes']['class'])) {
        $build['#attributes']['class'] = [];
      }
$label = $this->entityTypeManager->getDefinition($this->entityType)->getLabel();
    $target = $this->options['target'];

    // If the target does not contain tokens, try to load the entity and     // display the entity ID to the admin form user.     // @todo Use a method to check for tokens in     // https://www.drupal.org/node/2396607.     if (!str_contains($this->options['target'], '{{')) {
      // @todo If the entity does not exist, this will show the config target       // identifier. Decide if this is the correct behavior in       // https://www.drupal.org/node/2415391.       if ($target_entity = $this->entityRepository->loadEntityByConfigTarget($this->entityType, $this->options['target'])) {
        $target = $target_entity->id();
      }
    }
    $form['target'] = [
      '#title' => $this->t('@entity_type_label ID', ['@entity_type_label' => $label]),
      '#type' => 'textfield',
      '#default_value' => $target,
    ];

    $form['bypass_access'] = [
      '#type' => 'checkbox',
      
      $affected_dependencies[$type] = array_intersect($entity_dependencies[$type]$names);

      // If the dependencies are entities we need to convert them into objects.       if ($type == 'config' || $type == 'content') {
        $affected_dependencies[$type] = array_map(function D$name) use ($type) {
          if ($type == 'config') {
            return $this->loadConfigEntityByName($name);
          }
          else {
            // Ignore the bundle.             [$entity_type_id,, $uuid] = explode(':', $name);
            return $this->entityRepository->loadEntityByConfigTarget($entity_type_id$uuid);
          }
        }$affected_dependencies[$type]);
      }
    }

    // Merge any other configuration entities into the list of affected     // dependencies if necessary.     if (isset($entity_dependencies['config'])) {
      foreach ($dependent_entities as $dependent_entity) {
        if (in_array($dependent_entity->getConfigDependencyName()$entity_dependencies['config'])) {
          $affected_dependencies['config'][] = $dependent_entity;
        }
Home | Imprint | This part of the site doesn't use cookies.