Problem/Motivation

The Add button doesn't show if user doesn't have the permission to add a node in the bundle, and this is OK. It would be interesting to display a login button "login to add a " instead, in the way the forum module does it.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

erwangel created an issue. See original summary.

erwangel’s picture

Issue summary: View changes
erwangel’s picture

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 = Url::fromRoute('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,
    ];

astonvictor made their first commit to this issue’s fork.

astonvictor’s picture

Version: 1.2.2 » 1.x-dev
Status: Active » Needs review
astonvictor’s picture

Version: 1.x-dev » 2.0.x-dev
Status: Needs review » Needs work

need to update to support 2.0.x

astonvictor’s picture

Status: Needs work » Fixed

merged to 2.0.x

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

mandclu’s picture

As an FYI, the title of this issue is "Add option..." but it doesn't actually add an option. It changes the behavior for all sites, which many sites (including ones I manage) won't want. I have opened #3608144: Add configuration to enable login button to provide this as a configurable option, defaulting to FALSE (to preserve the existing behavior for sites using prior versions).