Mainly involves CCK UI (currently contrib), but will probably need adjustments in core hook_fieldable_info()

In anticipation for #413192: Make taxonomy terms fieldable, I started to look at how CCK UI could abstract its admin paths to tie to existing admin pages for any fieldable entity:
[base_path_for_obj_type_and_bundle]/fields,
[base_path_for_obj_type_and_bundle]/fields/[field_name]/edit,
[base_path_for_obj_type_and_bundle]/display,
etc...
CCK HEAD currently hardcodes paths for user and node bundles. Obviously temporary.

Base path patterns are different across current or to-come fieldable types:
node: admin/build/node-type/[bundle_name]
user: admin/user/settings (one single bundle)
vocabularies: admin/content/taxonomy/[vocab_id]

A solution might be to have each bundle specify its base admin path in hook_fieldable_info()'s 'bundles' entry.

Thoughts ?
+ if agreed, any volunteer ?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tstoeckler’s picture

Not 100% part of this issue, but still related:
I've been wondering if it made the whole Fields UI less complex if we were to provide one single page where users could define fields (e.g. admin/build/fields), that's just a regular list (like admin/content/node) with an "Add field" local task. Then the bundles would just have to implement creating instances of already existing fields. That would take a lot of stuff out of the current node type UI for instance (with CCK UI enabled), which is probably confusing for new users who know neither what a node nor a field nor ... is. I've been working on a mock-up maybe I'll post something here or in a different issue next week (given that I won't get my head ripped of for this proposal for some reason).
Again, sorry if this was off-topic.

yched’s picture

Hm, I'm a bit skeptical about the usability of one page listing all fields for all entities / bundles. How do you reorder your fields for 'page' node type ? Set the display settings for 'story' in teaser mode ?

But as I wrote in #414328-14: Converting core modules to provide fields leaves them with no UI, a community brainstorm on a good Field UI would be a very good thing IMO, so *please* post your mockups :-)
This issue is probably not the right place, because we need a short term solution with the current UI shortly after #413192: Make taxonomy terms fieldable lands.
I'd suggest a thread on http://groups.drupal.org/fields-core ?

bjaspan’s picture

This issue is primarily about menu paths, right? Instead of having hook_fieldable_info() return info for field_ui_menu() to use, what if field_ui() just exported callbacks intended to be called by other module's hook_menu()? So node_menu() would have an entry whose callback is field_ui_add_field() or whatever.

This would allow modules to define their field menus any way they want, even possibly writing their own wrappers around the field_ui callbacks if they want something crazy.

yched’s picture

Well, if you look at the part below foreach (field_info_fieldable_types() as $obj_type => $info) { in cck_menu(), that's non-minor, non-trivial code for every fieldable entity module to add...

Doing crazy things is still possible through hook_menu_alter(), but field_ui / cck providing sensible defaults menu paths would still be cool IMO.

yched’s picture

Plus: could be modified, I guess, but we also have a 'List of all fields' page at admin/build/fields, which includes links to the 'Configure links' page for the involved bundles - and we'd have no way to generate those links if the paths are entirely custom.
This 'Fields' page is far from optimal, but is still very handy - it's notably the only place where you have a clear vision on shared fields.

yched’s picture

Status: Needs work » Active
FileSize
19.87 KB
10.06 KB

Dirty 1st patch (patcheS, actually: one for core, one for CCK UI). Still need some polish, but it works and outlines the challenges:

- If we want Field UI screens to appear as primary tabs on the existing 'Edit [bundle]' page (edit node type, edit vocab), we need to piggyback its menu path pattern:
For node types, one "admin/build/node-type/[node-type]" path per existing node type.
For vocabs, one single "admin/content/taxonomy/%taxonomy_vocabulary" path with a placeholder for the vid.

- In the last case, we'll need both the 'path pattern' for menu items, and the 'real' path for each vocab, to be able to generate the actual 'edit field', 'remove field'... links.

- This also implies different format for the 'bundle name' received by the Field UI page callbacks
In the 1st case, the page callback receives a 'node-type' string, in the 2nd case, it receives a fully loaded $vocabulary object, from which we need to extract the 'bundle name'.
Note that it's a different thing from extracting a bundle name from a fieldable object (field_attach_extract_ids). Taxo terms are the 1st example of a fieldable entity where 'bundles' are actual data structures.

- Each set of Field UI pages need to use the same access perms as the main 'Edit [bundle]' page it ties to: administer content types, administer taxonomy, administer users, etc...

For now the patch adds all needed information as additional entries in hook_fieldable_info().
Arguably, we could add a drupal_alter('fieldable_info') (which we need anyway) and let CCK contrib add all UI-related properties on behalf of core modules. Drawback : those properties wouldn't get proper documentation in core.

yched’s picture

Status: Active » Needs review
FileSize
10.21 KB

Oops, user_fieldable_info() was incorrectly updated.
Apply with CCK patch in #6

Status: Needs review » Needs work

The last submitted patch failed testing.

yched’s picture

Status: Active » Needs review
FileSize
10.37 KB

fixes tests (typo in field_test.module menu paths for edit forms)

moshe weitzman’s picture

This approach looks good to me. A couple observations:

  1. when adding/editing a field on a term: Notice: Undefined index: name in cck_field_edit_form() (line 1162 of /Users/mw/contributions/modules/cck/includes/cck.admin.inc).
  2. I expected a Manage Fields link on each vocabulary on admin/content/taxonomy/
  3. I could not see any Manage Fields feature on the admin/user/settings.
  4. Would be nice to add Node/User/Term column to admin/build/fields. Make this table sortable. I think this page is here to stay :)
yched’s picture

New patches, fixed #10 1. and 3.

2: right, that would require we overwrite the admin/content/taxonomy page callback, like we do for admin/build/types.
I left that as a TODO for now.

4: True, but separate patch. To be frank, I can't really handle working on Field UI code.
As I (finally) admitted in a recent private mail, maybe we should indeed push Field UI in core to give the community an incentive to enhance it or propose better UI concepts.

Anyway, this wouldn't deprecate the code in those patches: the additional 'path info for bundles' will be needed anyway if we want Field UI to handle contrib entity types.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

For 2, I will eventually coerce tables into a renderable element that can then be altered in hook_page_alter. Thats better than taking over the whole menu callback.

I am pleased with this. This is the most important field ui patch we have in the queue now AFAIK. Lets do some committer strip search and commit. RTBC.

yched’s picture

Status: Reviewed & tested by the community » Needs work

Thanks Moshe :-)
Actually, still TODO: at least document the new hook_fieldable_info() properties.

yched’s picture

Status: Needs work » Needs review
FileSize
20.07 KB
12.53 KB

Updated PHPdoc for hook_fieldable_info() (+ uses taxonomy implementation as a more thorough sample code)
Can probably use a re-read, not all of it is trivial.

+ added 'access callback' in the admin info for bundles. Can be omitted, but I guess some contrib entities might have more complex access rules than just perm-based.

Also, the patch tries to reduce the confusion between machine name and human name in code by settling on 'label' for human names of entities and bundles (like field types, widgets, formatters and field instances do). Mainly affects the CCK side.

yched’s picture

Forgot to remove a TODO. The CCK patch is the same as in #14

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the fixes. Back to RTBC.

Bojhan’s picture

Has this an interface facing part?

moshe weitzman’s picture

The CCK patch has some UI it, though it doesn't touch the important flow when adding/editing a field. UI feedback is very much welcome before or after this patch lands. Some discussion at http://groups.drupal.org/node/23282

Bojhan’s picture

I spoke to yched yesterday about this as well, we need to be very cautious in moving the abstraction layer that fields introduce into the UI as well. Although mentioning that fields are also used somewhere else, could be useful - it might be hard to scan when you have 10+ content types, with loads of crossing fields.

Could you attach a screenshot, which part this patch does touch? As I see five screenshots, in the group discussion.

yched’s picture

FileSize
9.2 KB
9.68 KB
10.92 KB

Bohjan: Screenshots attached.

Note that this patch isn't about UI design discussions, though. It just updates the *current* CCK HEAD UI ('Manage fields', 'Display fields' tabs, as in CCK D6) to core HEAD with taxo fields now fieldable, and translates in code the fact that fieldable entities will have their own base UIs sprinkled in different parts of the menu tree: edit node type, edit vocabulary, ... Any Field UI, whatever shape it ends up having, will need to account for that, using more or less the information collected in this patch.

The goal here is just to keep CCK HEAD as a working UI, for people to actually use the Field API and provide a starting ground for the forthcoming design discussions.

Thus, I did not attach shots for the actual content of the 'Manage fields' / 'Display fields' pages, so as to keep the issue focused:-).

yched’s picture

The CCK patch had a typo. Reattaching both patches for clarity.
The core patch hasn't changed and is still RTBC.

Bojhan’s picture

What is the difference between manage and display? I would probably need to install CCK head, but the labels don't really explain what they are.

As much as this isn't a UI discussion, you are adding elements to the UI.

yched’s picture

OK, here are those shots, then. It's roughly the same as CCK D6.
- "Manage fields" is where you add fields to a bundle, reorder them, change their settings, remove them.
- "Display fields" is where you define fields display settings for the various display contexts ('build modes')
(note that 'the 'Exclude' column on the 'Display fields' page will go as soon as #367215: Remove 'exclude from $content' display setting gets in)

To be extra extra clear: please let's not discuss the content of those pages here. The sooner the patch gets in, the sooner this discussion can happen.

"You are adding elements to the UI" - not exactly. I'm making the current elements available where they currently miss :-)

Bojhan’s picture

So would it be possible to say in a future patch, remove the display fields tab - and move it under manage fields? I feel that we shouldn't make two tabs - it only confuses where you could find certain functionality. Instead to move it as a tab or something else under Manage fields (clearly not talking about design of that page yet).

yched’s picture

Well, it's doable if we can merge the functionality of both pages into one :-). Obviously we didn't succeed this in CCK D5/D6. I think vertical tabs might help us in D7.

But *really*, that's not the right issue to discuss any of this. The point here is to make it possible to attach a UI, whatever it is, to fieldable entities. Let's focus on getting this in asap, so that the discussion on the actual shape of the UI can be supported by actual code.

Bojhan’s picture

"make it possible to attach a UI, whatever it is, to fieldable entities" - yes to that! Sorry, sometimes it's hard as a non-programmer to grasp the abstractness of a patch.

catch’s picture

Status: Reviewed & tested by the community » Needs review

What's "taxonomy_bundle_name_from_menu_helper"? I see it in the API docs and taxonomy_fieldable_info() but it's not declared anywhere. It's also just a TODO in the CCK module, and seems like the taxonomy_get_vocabularies() in taxonomy_fieldable_info() makes it unnecessary anyway?

yched’s picture

Status: Needs review » Needs work

@catch: Hm, actually taxonomy_bundle_name_from_menu_helper() remained in the CCK patch. And, er yes, the PHPdoc is still TODO, forgot about that. CNW, then.

The point is: if we want field UI menu paths to appear as tabs on the 'Edit vocab Foo' page, they need to piggyback the admin/content/taxonomy%taxonomy_vocabulary/... menu path.
It means the Field UI page callback receives a fully loaded $vocab object from the menu system, but, being entity agnostic, it has no way to know that the bundle name it needs is in the $vocab->machine_name property.

I'm actually not really happy with that 'name of helper function' thing in hook_fieldable_info(). Best way would be to solve this as we solved the similar issue on $objects: 'id key', 'bundle key' in hook_fieldable_info(). But how would we name that ? 'bundle_name_in_bundle_object key' ?

yched’s picture

Side note:
UI-oriented summary of D7 Field API: http://groups.drupal.org/node/23545
Discussion thread: http://groups.drupal.org/node/23282

yched’s picture

Status: Needs work » Needs review
FileSize
19.78 KB
21.3 KB

Removed 'bundle helper' and taxonomy_bundle_name_from_menu_helper(), as explained at the end of #28:
hook_fieldable_info() now contains the name of the $bundle object's property that holds the bundle name, just like we do for fieldable $objects themselves.

- reshuffled the 'keys' in hook_fieldable_info() a little bit:

function hook_fieldable_info() {
  $return = array(
    'taxonomy_term' => array(
      'label' => t('Taxonomy term'),
      'object keys' => array(
        'id' => 'tid',
        'bundle' => 'vocabulary_machine_name',
      ),
      'bundle keys' => array(
        'bundle' => 'machine_name',
      ),
      'bundles' => ...,
    ),
  );
  return $return;
}

- added field_attach_extract_bundle(), similar to field_attach_extract_ids(). Each page callback in CCK uses it to transform the $bundle param handed by the menu system into a bundle name *string*

moshe weitzman’s picture

Core patch looks proper to me. I think it is RTBC once the test bot gives green light. Thats a very good indicator in this case that all is well. It would fail horribly if we screwed up field_attach API.

Status: Needs review » Needs work

The last submitted patch failed testing.

webchick’s picture

Status: Needs work » Needs review

Slave #24 was a bit possessed tonight.

catch’s picture

Status: Needs review » Reviewed & tested by the community

Read through the patch and it looks great to me as well, solves the taxonomy term/vocabulary issue nicely.

yched’s picture

"Slave #24 was a bit possessed tonight" - I'll try to say this outside of the issue queue, just once.

moshe weitzman’s picture

RTBC for a week now. Lets get moving on our plan to commit this and then the CCK UI as is. That consensus is at #414328-18: Converting core modules to provide fields leaves them with no UI and replies.

Status: Reviewed & tested by the community » Needs work

The last submitted patch failed testing.

yched’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
19.56 KB
21.76 KB

Rerolled.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Cool. I don't quite understand everything that's going on in this patch, but that's mostly due to my general ignorance regarding Field API stuff. The code is reasonably easy to follow, and has backing up of catch, yched, moshe, etc. This is holding up other stuff.

Committed to HEAD. Thanks, folks!

yched’s picture

Thanks webchick.

I committed the CCK part of the patch.

Status: Fixed » Closed (fixed)
Issue tags: -Fields in Core

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