- Issue created by @erwangel
- π«π·France erwangel
This was pretty easy to do. Here is the code if someone wants to make a patch. Just put this in the render function before the $element array. For a full solution, we'll also have to create a new field 'login_label' in the settings form to hold the 'Login to add your @bundle_label' chain int the way the 'Add a new entry' is done in defineOptions() and buildOptionsForm(). For those who can't wait for a patch, the same can be achieved in hook_preprocess_views_view: filter on $variables['display_id'] and work the $variables['header']['add_content_by_bundle'] array.
// Start new code if (!$access) { $bundle_info = \Drupal::service("entity_type.bundle.info")->getBundleInfo($entity_type->id()); $bundle_label = $bundle_info[$bundle_type]['label']; $this->options['label'] = $this->t('Login to add your @bundle_label', ['@bundle_label' => $bundle_label]); $url = new Url('user.login', [], ['query' => $params]); $access = $this->accessManager->checkNamedRoute('user.login', [], $account); } // End of new code // Assemble elements into a link render array. $element = [ '#type' => 'link', '#title' => $this->options['label'], '#url' => $url, '#options' => [ 'attributes' => ['class' => $classes], ], '#access' => $access, ];