ethercreative / sidebar-entrytypes

Easily switch between entry types in the entries section
MIT License
7 stars 2 forks source link

Add type Id to the new entry button #1

Open JorgeAnzola opened 5 years ago

JorgeAnzola commented 5 years ago

When you are in the overview of an entry type, for example in the company > portfolio (See image below), and you click the new entry button, a dropdown appears (Like in all entries) instead of going directly to the new entry edit page. Maybe adding ?typeId=x in the URL?

lukasIO commented 2 years ago

just checking in, is this repo still active? this request would make the plugin so much more user friendly!

alexjcollins commented 2 years ago

@lukasIO To be honest, we'd probably only address bugs at this stage - but i'll keep this here and if we have a spare bit of time, we can addsomething in to handle this.

lukasIO commented 2 years ago

appreciate the clarification, thanks! would you be open to PRs ?

alexjcollins commented 2 years ago

Yeah, absolutely :)

croxton commented 1 year ago

For anyone trying to implement this, here is a quick and dirty workaround:

Change this: https://github.com/ethercreative/sidebar-entrytypes/blob/239ebb81ab4bb518072bdfb1f9e0f28eea742959/src/SidebarEntryTypes.php#L75-L93

To this:

foreach ($entryTypes as $entryType) {
    $children[$i][] = [
        'key' => 'section:' . $entryType->uid,
        'label' => $entryType->name,
        'data' => [
            'has-structure' => true,
            'default-sort' => 'structure:asc',
            'type' => 'structure',
            'handle' => $entryType->handle,
            'entry-type' => true,
            // Add these lines -->
            'section' => $entryType->section->handle,
            'typeId' => $entryType->id
            // <-- end
        ],
        'criteria' => [
            'sectionId' => $entryType->sectionId,
            'type' => $entryType->handle,
            'editable' => false,
        ]
    ];
}

Now the current section handle and entry type ID are in the data attributes of the links in the sidebar, we can use JS to change the 'New entry' button to create an entry in the currently selected section and entry type. Injecting custom JS into the control panel can be done with this plugin: https://github.com/doublesecretagency/craft-cpjs

The JS to use is here: https://gist.github.com/croxton/e7dae90a447c27ce929a13dcebe2c0ca

It would be great if this could incorporated into the plugin.