Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

EntryIndex.$newEntryBtn doesn't update sources on selectSite #2925

Closed
Anubarak opened this issue May 26, 2018 · 0 comments
Closed

EntryIndex.$newEntryBtn doesn't update sources on selectSite #2925

Anubarak opened this issue May 26, 2018 · 0 comments

Comments

@Anubarak
Copy link
Contributor

Anubarak commented May 26, 2018

Description

The Craft.EntryIndex class doesn't properly update the available publishableSections in the $newEntryBtnGroup. Currently this code is executed to display all available Sections inside the New entry button, thus users can select all of their sections when they want to create a new entry - no matter if the section is even available in the current site or not. Here is the code

for (i = 0; i < this.publishableSections.length; i++) {
    var section = this.publishableSections[i];

    if (this.settings.context === 'index' || section !== selectedSection) {
        href = this._getSectionTriggerHref(section);
        label = (this.settings.context === 'index' ? section.name : Craft.t('app', 'New {section} entry', {section: section.name}));
        menuHtml += '<li><a ' + href + '">' + Craft.escapeHtml(label) + '</a></li>';
    }
}

publishableSections contains all sections, so it doesn't care if they are enabled or not

publishableSections: [
    {% if isInstalled and currentUser is defined and currentUser %}
        {% for section in craft.app.sections.getEditableSections() %}
            {% if section.type != 'single' and currentUser.can('createEntries:'~section.id) %}
                {
                    id: {{ section.id }},
                    name: "{{ section.name|t('site')|e('js') }}",
                    handle: "{{ section.handle|e('js') }}",
                    type: "{{ section.type }}",
                    entryTypes: [
                        {% for entryType in section.getEntryTypes() %}
                            {
                                id: {{ entryType.id }},
                                name: "{{ entryType.name|t('site')|e('js') }}",
                                handle: "{{ entryType.handle|e('js') }}"
                            }{% if not loop.last %},{% endif %}
                        {% endfor %}
                    ]
                }{% if not loop.last %},{% endif %}
            {% endif %}
        {% endfor %}
    {% endif %}
],

It just checks if the user can edit the section or not.

Steps to reproduce

  1. Create multiple sites and multiple different sections
  2. Disable some of those sections for certain sites
  3. Click on the "New Entry" button and see all those sections as available sources no matter if they are enabled for the current selected site or not

Steps to fix this

  1. include the ids of all available sites in the publishableSections object
  2. include an additional condition if (this.settings.context === 'index' || section !== selectedSection) { if the current selected siteId this.siteId is in the array of site ids.
if ((this.settings.context === 'index' || section !== selectedSection) && section.availableSites.includes(this.siteId) {

and

availableSites: {{ section.getSiteIds|json_encode|raw }},
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant