Problem/Motivation

JsonapiResourceConfig uses the AdminHtmlRouteProvider. This adds entity routes with a _title_callback of, for example, \Drupal\Core\Entity\Controller\EntityController::editTitle.

In core's HtmlRenderer, we see:

protected function prepare(array $main_content, Request $request, RouteMatchInterface $route_match) {
    // Determine the title: use the title provided by the main content if any,
    // otherwise get it from the routing information.
    $get_title = function (array $main_content) use ($request, $route_match) {
      return $main_content['#title'] ?? $this->titleResolver->getTitle($request, $route_match->getRouteObject());
    };

And in JsonapiResourceConfigForm we see:

    // If we are editing an entity we don't want the Entity Type and Bundle
    // picker, that info is locked.
    if (!$entity_type_id || !$bundle) {
      if (!$resource_id) {
        // We can't build the form without an entity type and bundle.
        throw new \InvalidArgumentException('Unable to load entity type or bundle for the overrides form.');
      }
      [$entity_type_id, $bundle] = explode('--', $resource_id);
      $form['#title'] = $this->t('Edit %label resource config', ['%label' => $resource_id]);
    }

So as long as the form title is set, we will not call the title resolver. But as soon as the form is altered to drop the title or another route with a default title callback is visited and the returned build does not contain a title, we will call the title callback. At that point, we will get to, for example:

  public function editTitle(RouteMatchInterface $route_match, ?EntityInterface $_entity = NULL) {
    if ($entity = $this->doGetEntity($route_match, $_entity)) {
      return $this->t('Edit %label', ['%label' => $entity->label()]);
    }
  }

Which will crash because we're providing NULL for a placeholder.

Steps to reproduce

Comment out the line that sets the form title and try to visit an override form at admin/config/services/jsonapi/resource_types/foo/edit and witness a crash.

Proposed resolution

Either provide labels for JsonapiResourceConfig, ironically undoing #3265286: JsonapiResourceConfig Declares a `label` Entity Key that It Does Not Use or Maintain, or use a custom route provider that strips or replaces the default title callbacks.

Remaining tasks

  1. Decide approach
  2. Carry out the change

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Comments

kristiaanvandeneynde created an issue.