Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Re-structuring #1445

Merged
merged 141 commits into from
Mar 17, 2020
Merged

Re-structuring #1445

merged 141 commits into from
Mar 17, 2020

Conversation

jasonvarga
Copy link
Member

@jasonvarga jasonvarga commented Feb 27, 2020

This PR contains a bunch of improvements to Structure-related areas.

Overview

Structures have been split into Navigation and Collection Structures.

Structures themselves still technically exist, but are more of an abstract code level thing.

Navigation

Navigation (or Navs) are now the things you were creating up until now.

A navigation is a type of structure that lives in your content/navigation directory. It's just a bunch of links and/or references to entries. Previously, you'd have a structure and you'd choose "navigation" as it's purpose. It replaces "Structures" in the CP sidebar.

image

Collection Structures

Associating a structure with a collection was one of the biggest areas of confusion.

Now, instead of needing to create a structure and link that structure from the collection, you can simply opt to have a collection "be organized into a structure".

The structure will be stored in the collection's YAML file:

# content/collections/pages.yaml
title: Pages
route: '{parent_uri}/{slug}'
blueprints:
  - page
structure:
  max_depth: 4
  tree:
    -
      entry: id-of-home
    -
      entry: id-of-blog-page

In the control panel, you will be able to easily toggle between the tree view and the table view.

image

Collection Ordering

Now that's simpler to define the structure of your entries, we've merged the concept of "ordering" into the structure.

Being orderable and being structured is basically the same thing. You're just dragging and dropping entries into the order you want. The only difference is that a structure lets you nest them.

So now instead of an explicit orderable: true item in your collection, you just enable the structure, and set max_depth: 0.

This removes the need for the current entry_order array in the collection's yaml file. If at some point you want to change from a linear order to a nested one, you can just increase the max depth.

In terms of UX, when you have a structure with a max depth of 1, you will get the existing table list view with drag handles.

Structure Root

The expects_root and root: some-id on a structure was also confusing.

The expects_root setting was there to control the UI, especially in the case where your structure didn't have any pages in it yet.
We had a separate root to prevent you from adding child pages to it.

Now, the "root" page is just simply part of the tree, and root is a boolean that defines whether the first item should be considered the root.

root: true
tree:
  -
    entry: home-page
  -
    entry: blog-page

This prevents you from needing to move the root in and out of the tree when you change the expects_root setting.

Redirects

You were already able to add redirect: somewhere to an entry to have a redirect be triggered when you visit its url. Now, the actual URL will be its target. ie. when you do {{ url }} in the front-end, you'll get the redirected URL.

This also means that if you use the entry query builder (or a feature that uses it under the hood), then there may be more than one entry with the same url. Not necessarily a problem, just something to be aware of.

Collection Structure Links

Piggybacking off redirects, this is how you'd create redirects and links within a collection's structure. A redirect would simply be another actual entry. It would just have a redirect variable in it.

When you click the "create entry" button in a collection, you'll get a "Link" option, as if it were one of your blueprints. This will give you the create entry screen with a title and redirect field.

If you create an entry_link blueprint, you can override these fields.

Collection Tag and Links

By default, link entries (any entries with a redirect value) will be excluded from the collection tag. You can include them by adding the links="true" (or redirects="true") parameter.

Permissions

Permissions are now attached to navs, instead of structures.

The existing reorder {collection} entries permission will be used to control whether the tree can be edited.

Control Panel "Nav"

We've changed Statamic\Facades\Nav to now deal with these new navs.

The existing Nav class which let you add items to the CP's sidebar has been moved to Statamic\Facades\CP\Nav.

Breaking changes

These are obviously breaking changes, so we will provide a way for you to get updated without you having to do it all manually.

Closes #1094

- Collection show view now shows a page tree if the collection has a structure.
- You can switch between the tree and regular listing. It'll remember it in local storage.
- Structure::make() accepts a handle.
- $structure->handle() can be passed null and it'll still be chainable
- The page tree component just does the page tree stuff, emits events, and just leaves the buttons etc to be handled in a parent component.
- Page tree loads intial pages with ajax instead of passing the initial values. Unnecessary maintenance burden, not a huge deal.
…erwise it just opens the link pane immediately.
- A structure-managed collection now has the structure defined in the collection's yaml file
- Structure::find() and findByHandle() expect "collection::{handle}" as the handles when looking for a collection structure
- Structure::all() merges in collection structures.
- Page::setRoute() should allow a null route. The test wasn't catching this because the Structure::collection() logic was causing a collection to always be returned. (first where structurehandle is null always returned a match)
- Store the collection handle alongside structure page uris. The urls only exist for collection-structures. Not nav-structures.
…into Facades\CP\Nav in preparation for more upcoming nav changes
- The root lives in the tree array. This is so that if you change whether its expecting a root, you don't have to also move the root.
- The root/parent is pulled out of the array if its expecting a root
- The primary reason it was a separate variable before was so you couldn't give it child pages. Just add an exception now.
- Navs are now the things stored in the stache and in yaml files
- You can query Navs specifically, instead of getting all structures and filtering them manually.
- Structure facade and repo is still a thing, but it just combines navs and collection structures.
- Structured entry URIs are just stored on the entry instead of its own index. They get updated when the collection is updated.
- expects_root is now just a root boolean
@jackmcdade
Copy link
Member

jackmcdade commented Mar 13, 2020

A few bugaroos 🐛

  • Turning on orderable on a new collection will throw missing tree errors when you try to save
  • Picking an entry in the Redirect Fieldtype will show the ID instead of the title
  • Redirect fieldtype's dropdown isn't wide enough to show the words "First Child"
  • Tree view's "Create Entry" button should say "Create..." or use the new btn-group style with a dropdown because it wasn't clear that was a Create Link option until you see it there.
  • You can Add Child Link to an entry in a Navigation but like above it wasn't clear you could add link to an entry from the Add Link button.

@chrisbjr
Copy link
Contributor

Hi @jasonvarga already getting errors after this was merged :) is there a way to migrate to this re-structure automatically like you mentioned?

@jasonvarga jasonvarga deleted the feature/structure-redux branch May 5, 2020 19:33
jasonvarga referenced this pull request Apr 13, 2021
…i, so child page's uris continue on from the parent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Activating Site on Page returns 404
3 participants