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

Bring menu item/reference selection into core and make a new Reference selector widget #961

Open
bennothommo opened this issue Aug 26, 2023 · 3 comments

Comments

@bennothommo
Copy link
Member

Package targeted

Both

Description

I was hoping to implement this as a PR immediately, but it's become a little bigger than I had imagined so I think it's best we scope this out.

Currently, this Menu Item selector/editor is only available when the Pages plugin is installed:

image

However, I feel (and I seem to recall the other maintainers feeling the same) that this is a well useful tool that could be used in other areas, and as such should be brought into core. Ideally, I'd like to create a new FormWidget called "Reference" which brings up a (simplified) version of this selector and calls for all plugin references (the pages.menuitem.* events), allowing the user to select a reference for cross-linking, or providing an ability for a field to contain either a straight URL or a dynamic reference to a plugin item. This would make it similar to Wordpress' link picker:

image

Storage

There's two ways we could store these references:

  • As a JSON or serialized object. Seems a bit "unclean" in my opinion, but would be much easier. Should be stored as an object to allow for URL changes on the target references. The object would need to be decoded/unserialized prior to use - for forms/models, we could do this automatically. For Twig, it might need a filter like we have for media items.
  • Alternatively, we could store it as an "attachment" relation. Would require a database call to get the relations however, and Halcyon has no relation capability yet, so would require us to add - at a minimum - attach relation capabilities to Halcyon. Doing this would pave the way to allow us to eliminate another issue: people being unable to use fileupload widgets with Halcyon objects.

Reference FormWidget

The Reference form widget should, at a minimum, provide the following fields from the menu item editor above:

  • Type
  • Reference
  • Allow nested items?
  • Replace with children?

It should return a class representing the reference: ideally, this class should be able to determine if there's multiple references or not, and return URLs for each.

It may be prudent to allow the form widget to be configured to accept only one reference (therefore not allowing nested items), or accept multiple.

Other places to implement this

The same picker should be made available for the Rich Editor and Markdown Editor's link buttons. Currently, I believe, these both allow you to just pick a CMS page.

Will this change be backwards-compatible?

Yes, backwards compatibility would be maintained.

Ideally, we'll need to use new event names, but call the old event names for compatibility and merge the results. I propose the following:

  • references.getTypes (replaces pages.menuitem.listTypes, gets the available reference types for the "Type" dropdown)
  • references.getReferences (replaces pages.menuitem.getTypeInfo, gets the available references for a particular type)
  • references.resolve (replaces pages.menuitem.resolveItem, resolves a reference object)
@josephcrowell
Copy link
Sponsor Contributor

josephcrowell commented Aug 26, 2023

OH God yes. I rarely use static pages but use the static pages menu editor all the time. I'd love for it to be extensible so I can store other data such as related font icons or extend it to recognize Passage permissions.

@LukeTowers
Copy link
Member

See https://docs.octobercms.com/3.x/element/form/widget-pagefinder.html, it has some concepts that I like. Could also be very useful for dealing with the issues of switching media sources in different environments, i.e. we could use it for the inline images / files / document links in content to make switching between environments seemless.

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants