Verified Commit db906a7b authored by Jess's avatar Jess
Browse files

Issue #3328066 by rpayanm, joachim: simplify logic in ConfigManager::getEntityTypeIdByName()

(cherry picked from commit 75035a0f)
parent ae3bd364
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -7,7 +7,6 @@
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Config\Entity\ConfigEntityTypeInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ExtensionPathResolver;
use Drupal\Core\Serialization\Yaml;
@@ -120,10 +119,13 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, Con
   * {@inheritdoc}
   */
  public function getEntityTypeIdByName($name) {
    $entities = array_filter($this->entityTypeManager->getDefinitions(), function (EntityTypeInterface $entity_type) use ($name) {
      return ($entity_type instanceof ConfigEntityTypeInterface && $config_prefix = $entity_type->getConfigPrefix()) && strpos($name, $config_prefix . '.') === 0;
    });
    return key($entities);
    foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
      if (($entity_type instanceof ConfigEntityTypeInterface && $config_prefix = $entity_type->getConfigPrefix()) && str_starts_with($name, $config_prefix . '.')) {
        return $entity_type_id;
      }
    }

    return NULL;
  }

  /**