ConfigNameException example


  public static function validateName($name) {
    // The name must be namespaced by owner.     if (!str_contains($name, '.')) {
      throw new ConfigNameException("Missing namespace in Config object name $name.");
    }
    // The name must be shorter than Config::MAX_NAME_LENGTH characters.     if (strlen($name) > self::MAX_NAME_LENGTH) {
      throw new ConfigNameException("Config object name $name exceeds maximum allowed length of " . static::MAX_NAME_LENGTH . " characters.");
    }

    // The name must not contain any of the following characters:     // : ? * < > " ' / \     if (preg_match('/[:?*<>"\'\/\\\\]/', $name)) {
      throw new ConfigNameException("Invalid character in Config object name $name.");
    }
  }

  public function preSave(EntityStorageInterface $storage) {
    parent::preSave($storage);

    // Only handle renames, not creations.     if (!$this->isNew() && $this->getOriginalId() !== $this->id()) {
      $bundle_type = $this->getEntityType();
      $bundle_of = $bundle_type->getBundleOf();
      if (!empty($bundle_of)) {
        throw new ConfigNameException("The machine name of the '{$bundle_type->getLabel()}' bundle cannot be changed.");
      }
    }
  }

  /** * Returns view or form displays for this bundle. * * @param string $entity_type_id * The entity type ID of the display type to load. * * @return \Drupal\Core\Entity\Display\EntityDisplayInterface[] * A list of matching displays. */
Home | Imprint | This part of the site doesn't use cookies.