Problem/Motivation

Currently the only way to relate content entities like users and nodes is from the group admin content page, but sometimes you would like to have a multiple groups admin user able to relate content with multiple groups at the same time.

It'd also be nice to be able to display all the groups that a given piece of content is associated with.

Proposed resolution

Provide a computed field ready to be used on all the content entity types supported by the GroupContentEnabler Plugin, out of the box the group module provides support for users and nodes (gnode submodule).

https://www.drupal.org/project/entitygroupfield provides this field which respects the groups permissions.

Remaining tasks

Immediate

Next phase

Go through remaining tasks and #210 and split off child issues in the new queue, then update the summary to cross off that item with a [#x] link to the new issue.

  1. #85 / #109 fixed in #176 or before
  2. #177.2a #3152725: Don't lock the group select widget on node/add forms
  3. #90.4a Fixed in #91.
  4. #90.8: Users should only see the parts of the widget that they can use. #3152723: Hide aspects of the widgets that a user doesn't have permission to use
  5. #90.9 (see also #117 and #147) Fixed in #160.
  6. #90.10: Needs tests #3152293: [META] Add test coverage for Entity Group Field
  7. #113
  8. #127 and #128 Fixed in #155.
  9. #146 Fixed in #158
  10. #149 (all) Fixed in #152.
  11. #150, #159: Tokens don't work. Fixed in #180.
  12. #162: gcontent-field.admin.css shouldn't use .js selectors Fixed in #180.
  13. #164 and #166.a: The new widget and formatter(s) shouldn't be available on regular entity_reference fields. Fixed in #176
  14. #183: Add docs. #3152713: Add documentation for Entity Group Field
  15. #187: Allow this to not be read-only? #3152714: Consider if this field can be set as not read-only
  16. #190.2: Permission problems for 'Advanced Outsider Permissions' users. #3152715: Permission problems for 'Advanced Outsider Permissions' users
  17. #191: Uninstall breaks field configs #3152716: Uninstall breaks field configs
  18. #194: Namespace collision with "group_content" field_group #3152717: Rename field ID from "group_content" to "entitygroupfield"
  19. #195: Cardinality bugs with widget #3152719: Group cardinality bugs with widget
  20. #196.1: Widget should render as a details container ("fieldset") #3152720: Widget should render as a details container
  21. #196.2: Why is the widget using tabledrag? #3152722: Widget should not use tabledrag
  22. #210 #3152724: Improve architecture per kristiaanvandeneynde

User interface changes

  • New field called "Group Content" available in all content entities supported for group via GroupContentEnabler plugin.
  • New widget called "Group selector" which provide a good UX for editing the relations with groups. Makes it possible to alter the group content fields especially useful for user roles in groups.
  • New formatters:
    • "Parent group rendered entity": allows you to show the rendered group entity (with an option to control the view_mode to use).
    • "Parent group ID": allows you to show the group entity ID.
    • "Parent group label": allows you to show the group entity label (with an option to make the label a link to the group or not).

Data model changes

None (really). There's a new field, but it just gets stored in the default Drupal Way(tm).

Original report by @jazzfiction

There are times where I would like to add a group relationship to content from outside of Groups itself. Examples would be adding a large amount of content inside the Content area for various groups, to making rules where if a taxonomy term is applied to a piece of content, then the rule would relate that content to a group.

As of right now, I haven't found a way to do that. I have tried adding entity reference fields to content types, trying to have rules automatically assign content group relations when certain condition arise, to trying to create a page like the add content page where all of the references are listed, and I can then add or delete them.

All I am trying to do is not have to go through various groups to try to modify a relationship when I want edit it as there will be eventually be many groups in my site. It may be that I am missing the obvious, as I am fairly new to modern versions of Drupal, as the last version I really used is D5. If this can be added to Groups, that would be great, or if this feature already exists, can somebody point me in the right direction?

CommentFileSizeAuthor
#223 interdiff_215_223.txt1.11 KBquentin massez
#223 group-field_to_view_and_edit_content_groups-2813405-223.patch70.74 KBquentin massez
#217 group-field_to_view_and_edit_content_groups-2813405-215.patch70.7 KBarnaud-brugnon
#215 group-field_to_view_and_edit_content_groups-2813405-215.patch.txt70.7 KBarnaud-brugnon
#190 Screen Shot 2019-07-25 at 2.31.38 PM.png63.41 KBjazzfiction
#190 Screen Shot 2019-07-25 at 2.30.19 PM.png126.03 KBjazzfiction
#190 Screen Shot 2019-07-25 at 2.30.11 PM.png100.07 KBjazzfiction
#181 Screen Shot 2019-07-10 at 8.59.05 PM.png17.62 KBjidrone
#181 Screen Shot 2019-07-10 at 8.58.48 PM.png17.08 KBjidrone
#180 interdiff_176-179.txt2.65 KBjidrone
#180 group-field_to_view_and_edit_content_groups-2813405-179.patch70.7 KBjidrone
#176 2813405.170_176.interdiff.txt5.57 KBdww
#176 2813405-176.group_content_field.patch70.95 KBdww
#170 2813405.163_170.interdiff.txt5.64 KBdww
#170 2813405-170.group_content_field.patch70.52 KBdww
#167 Capture d’écran du 2019-07-04 01-25-23.png82.69 KBzenimagine
#163 2813405.162_163.interdiff.txt996 bytesdww
#163 2813405-163.group_content_field.patch69.91 KBdww
#162 2813405.161_162.interdiff.txt2.53 KBdww
#162 2813405-162.group_content_field.patch69.9 KBdww
#161 2813405.159_161.interdiff.txt553 bytesdww
#161 2813405-161.group_content_field.patch69.89 KBdww
#160 2813405.158_159.interdiff.txt6.4 KBdww
#160 2813405-159.group_content_field.patch69.89 KBdww
#158 2813405.155_158.interdiff.txt1.12 KBdww
#158 2813405-158.group_content_field.patch67.22 KBdww
#155 2813405.142_155.interdiff.txt5.2 KBdww
#155 2813405.152_155.interdiff.txt3.14 KBdww
#155 2813405-155.group_content_field.patch67.19 KBdww
#152 2813405.151_152.interdiff.txt427 bytesdww
#152 2813405-152.group_content_field.patch67.03 KBdww
#151 2813405.142_151.interdiff.txt2.41 KBdww
#151 2813405-151.group_content_field.patch67.07 KBdww
#149 2813405-149.empty-select.png39.08 KBdww
#147 2813405-147.90-9.group-selector-choices.png49.61 KBdww
#147 2813405-147.90-9.group-selector.png60.8 KBdww
#147 2813405-147.90-9.select.png53.65 KBdww
#147 2813405-147.90-9.checkboxes.png42.34 KBdww
#147 2813405-147.90-9.autocomplete.png53.22 KBdww
#147 2813405-147.90-8.png37.82 KBdww
#146 group-field_to_view_and_edit_content_groups-2813405-146.patch66.51 KBmichfuer
#146 interdiff_142-146.txt1.23 KBmichfuer
#142 interdiff_124-142.txt2.99 KBjidrone
#142 group-field_to_view_and_edit_content_groups-2813405-142.patch66.49 KBjidrone
#139 Capture d’écran du 2019-05-24 03-04-55.png97.69 KBzenimagine
#139 Capture d’écran du 2019-05-24 03-04-34.png98.49 KBzenimagine
#139 Capture d’écran du 2019-05-24 03-03-46.png292.64 KBzenimagine
#135 Capture d’écran du 2019-05-19 21-23-34.png9.07 KBzenimagine
#134 Capture d’écran du 2019-05-19 21-23-14.png30.08 KBzenimagine
#128 null-coalesce.txt3.6 KBcatch
#127 null-coalesce.txt914 bytescatch
#124 interdiff_123-124.txt925 bytesjidrone
#124 group-field_to_view_and_edit_content_groups-2813405-124.patch66.62 KBjidrone
#123 2813405.91_123.interdiff.txt8.77 KBdww
#123 2813405-123.patch66.8 KBdww
#122 group-field_to_view_and_edit_content_groups-2813405-122.patch0 bytesjidrone
#99 group-field_to_view_and_edit_content_groups-2813405-99.patch13.09 KBbalbuf
#91 interdiff_87-91.txt19.36 KBjidrone
#91 group-field_to_view_and_edit_content_groups-2813405-91.patch65.68 KBjidrone
#90 2813405-90.group-member.node-add.png44.39 KBdww
#90 2813405-90.group-admin-invalid-group-already-in-some.png131.32 KBdww
#90 2813405-90.group-admin-invalid-first-group.png41.8 KBdww
#90 2813405-90.group-admin.node-add.png55.23 KBdww
#87 interdiff_81-87.txt881 bytesjidrone
#87 group-field_to_view_and_edit_content_groups-2813405-87.patch59.33 KBjidrone
#81 interdiff_80-81.txt777 bytesjidrone
#81 group-field_to_view_and_edit_content_groups-2813405-81.patch59.35 KBjidrone
#80 interdiff_69-80.txt3 KBjidrone
#80 group-field_to_view_and_edit_content_groups-2813405-80.patch59.17 KBjidrone
#77 Capture d’écran du 2019-01-21 11-10-34.png72.67 KBzenimagine
#77 Capture d’écran du 2019-01-21 11-09-46.png118.68 KBzenimagine
#71 Capture d’écran du 2018-12-22 15-59-37.png118.85 KBzenimagine
#71 Capture d’écran du 2018-12-22 15-59-22.png89.03 KBzenimagine
#69 Screen Shot 2018-12-21 at 11.43.45 PM.png13.98 KBjidrone
#69 group-field_to_view_and_edit_content_groups-2813405-69.patch58.56 KBjidrone
#68 Capture d’écran du 2018-12-21 18-34-34.png169.9 KBzenimagine
#66 group-field_to_view_and_edit_content_groups-2813405-66.patch56.05 KBjidrone
#65 Capture d’écran du 2018-12-21 06-27-55.png135.74 KBzenimagine
#64 group-field_to_view_and_edit_content_groups-2813405-64.patch56.68 KBjidrone
#62 gr.png109.79 KBzenimagine
#61 Capture d’écran du 2018 12 19 20 48 32.png127.04 KBzenimagine
#60 Capture d’écran du 2018-12-19 19-39-30.png125.58 KBzenimagine
#59 group-field_to_view_and_edit_content_groups-2813405-59.patch58.23 KBjidrone
#58 Capture d’écran du 2018-12-19 15-38-45.png109.36 KBzenimagine
#57 Capture d’écran du 2018 12 19 14 47 15.png962.58 KBzenimagine
#57 Capture d’écran du 2018 12 19 14 47 01.png89.06 KBzenimagine
#57 Capture d’écran du 2018 12 19 14 46 23.png90.77 KBzenimagine
#51 group-field_to_view_and_edit_content_groups-2813405-51.patch57.67 KBjidrone
#45 Capture d’écran du 2018 12 14 19 52 33.png130.11 KBzenimagine
#45 Capture d’écran du 2018-12-14 19-53-27.png90.17 KBzenimagine
#44 group-content-outside-groups-2813405-44.patch59.04 KBjidrone
#43 Capture d’écran du 2018 12 13 16 44 20.png323.03 KBzenimagine
#43 Capture d’écran du 2018 12 13 16 44 05.png196.01 KBzenimagine
#42 Capture d’écran du 2018 12 13 15 56 16.png41.43 KBzenimagine
#40 group-content-outside-groups-2813405-40.patch59.05 KBjidrone
#39 Capture d’écran du 2018-12-13 12-04-32.png141.17 KBzenimagine
#39 Capture d’écran du 2018-12-13 11-51-25.png137.08 KBzenimagine
#39 Capture d’écran du 2018-12-13 11-51-08.png41.92 KBzenimagine
#39 Capture d’écran du 2018-12-13 12-02-19.png104.85 KBzenimagine
#39 Capture d’écran du 2018-12-13 12-01-44.png103.48 KBzenimagine
#37 group-content-outside-groups-2813405-36.patch58.22 KBjidrone
#34 group-content-outside-groups-2813405-34.patch58.09 KBjidrone
#30 Capture d’écran du 2018-12-11 15-48-06.png131.27 KBzenimagine
#30 Capture d’écran du 2018-12-11 15-47-10.png129.94 KBzenimagine
#22 group-content-outside-groups-2813405-22.patch56.41 KBjidrone
#22 Screen Shot 2018-12-07 at 12.41.12 PM.png24.91 KBjidrone
#13 Capture d’écran du 2018-11-29 17-27-56.png83.18 KBzenimagine
#12 Capture d’écran du 2018-11-29 17-15-55.png79.75 KBzenimagine
#12 Capture d’écran du 2018-11-29 17-14-37.png455.23 KBzenimagine
#12 Capture d’écran du 2018-11-29 17-05-36.png827.27 KBzenimagine
#5 social_group.zip132.41 KBzenimagine
#3 group-content-outside-groups-2813405-3.patch17.01 KBjidrone

Comments

jazzfiction created an issue. See original summary.

flodevelop’s picture

Maybe you could use basic relationship between content and group without activate the gnode submodule.
Then the groups is like a taxonomy. But if you do that, you don't have group content so i think you can't manage the group permissions and roles on this group type and other great features.

Or you can code a custom module that check your fields values when insert or update the node content so you can manage the relationship (group content) between your content and the goup.
For example, you can add a user to a group, it is the same process for the content i think :

function group_user_autocreate_entity_update(Drupal\Core\Entity\EntityInterface $entity) {
  # check the type
  $entity_type_id = $entity->getEntityTypeId();

  switch ($entity_type_id) {
    # is it a user ?
    case 'user':
      $group_main_id = $entity->get('field_group')->getString();

      # get the main group
      $this_group = Group::load($group_main_id);

      # add user to the group, this function already check if user is member of this group
      $this_group->addMember($entity);
      break;
  }
}
jidrone’s picture

Version: 8.x-1.0-beta4 » 8.x-1.x-dev
Category: Support request » Feature request
Status: Active » Needs review
Related issues: +#2931801: Set Group Membership on User Form, +#2885162: Add a new user and assign it automatically to the group
StatusFileSize
new17.01 KB

Hi Everyone,

I create a patch with a group submodule which provide this functionality, I already tested it in nodes and users.
The submodule requires Inline Entity Form, once enabled you should see a fieldset called "Group Options" in the entity form and it also respect the groups permissions.

anairamzap’s picture

Hi,
I've tried the patch in #3 and its adding the expected functionality.

Steps I've followed:
1. Apply patch
2. Enable group, gnode, and the new submodule "gcontent" provided by patch (please note that new submodule has a dependency on inline_entity_form so you will need that module too).

Once the Content and User plugins are enabled for the group type, you I get a new "Group Options" fieldset on the Node add/edit and User add/edit forms. For the User form it correctly adds the new/existing user to the group. For the node add/edit it correclty assigns the node as a Group Content.

Also, If you have fields on the group type > content/user, these fields will be displayed inside the Group Name fieldset.

@jidrone Iván, one tiny thing I've noted is that if you don't have any fields set on the group available content config, you still get the Group Name fieldset but when you expand it is empty. Maybe we can display a message saying something like "This bundle doesn't have any configurable fields".

zenimagine’s picture

StatusFileSize
new132.41 KB

Thank you for this patch that will greatly simplify the group for my users.

I will test it and I will make a return.

There is the OpenSocial distribution for Drupal 8 which has perfectly integrated this functionality. You can test on this demo site:

https://www.drupal.org/project/social

https://demo.getopensocial.com/

Here is the custom module they created, I did not test it (do not install it in production) :

"zip"

zenimagine’s picture

@jidrone I just tested the sub module and it works well.

But there is some missing parameter that is not configurable:

- On my site the group must be required.

- On my site, the content can only be assigned to one group. So you need a selection list instead of autocomplete.

- This relationship with the group must be a field, to customize its position in the node edit form and render in twig.

- The relationship feature should be disabled in the group tab. Currently a user can add nodes in he is not the author to his group and this is a big problem.

See the comment #5

scotwith1t’s picture

@zenimagine i had a few of the same concerns and @jidrone is I believe refactoring to make this be a true field so you can configure things like Required, move the field around in the UI, perhaps even change the widget. I like auto-complete as the default since a site with lots of groups being all crammed into one select list can cause problems, but having it be configurable would be another benefit of this being a field.

zenimagine’s picture

@scotself the example module for open social displays the field with a selection list. This limits the content to a single group.

One could also mention Drupal Commerce with products that contain a store field. It can be configured in autocompletion or selection.

This is very good news if another patch is in development. I can not wait to test it.

Are you planning to disable the relationship tab and link links in groups? There should be the link add nicely.

dalra’s picture

The relationship feature should be disabled in the group tab. Currently a user can add nodes in he is not the author to his group and this is a big problem.

A better way would be to solve things separately and create new permissions as requested in #2771065: Group Node: Only authors should be able to create Gnodes for their nodes:
- Add own existing content
- Add any existing content

jidrone’s picture

Hi Everyone,

Yes, I'm developing another patch, the following are the improvements and reasons behind each:

Extrafield instead of Field type:
To allow admins to customize its position in the entity edit form, I will provide it as an extra field which will only appear on "manage form display" tab, I prefer that instead of the creation of a new field type because I think it's an overhead to have schema, storage and display functionality we won't use.

Configurable settings by Content Plugin:
Currently the group module has this form "admin/group/settings", which only have the option "Use admin theme". I will use this form to add some configurations for the field like: required, allow multiple, widget: select or autocomplete.

Permission to access to the field:
I'm adding a permission to access to the field, especially useful if you want to avoid anonymous user to see it in registration form.

I agree with @dalra to manage all the access related things with permissions, because this patch takes care of groups permissions.

zenimagine’s picture

@jidrone It's awesome.

Can the field appear in the display ?

In the twig of my nodes, I want to display a link or rendered entity to the parent group.

zenimagine’s picture

Here is an example :

- In the screenshot of my product, I added above the dotted line the parent store. Drupal Commerce adds a field in the display of my product.

- In the screenshot of my article, I added the parent group above the dashed line. But I have to use views and EVA to get that (it's complicated). Adding a group field to the node view will be much simpler.

zenimagine’s picture

jidrone’s picture

Hi @zenimagine,

I was thinking about your last request, in case we need to provide a display for the field is best to create a field type to have formatter settings to choose a view mode for the group.

So the following could be a possible approach:

  • Change the submodule name to 'gcontent_field' and label to "Group Content Field" to be more related about what module does.
  • Create a field type which will store the group_content_id.
  • Create 2 widgets for the field: select and autocomplete.
  • Create 2 formatter for the field: rendered entity and rendered_group.
jidrone’s picture

Status: Needs review » Needs work
zenimagine’s picture

@jidrone It seems to me very good.
Have you watched how the Open Social custom module works?
It could perhaps serve as a basis.

dalra’s picture

Create 2 widgets for the field: select and autocomplete.

Sounds great!
There also needs to be an option to remove the content from the group.
In the select it could be a None option and maybe a checkbox next to the autocomplete field.

zenimagine’s picture

@jidrone the module should verify that the user has already created a group before creating a new node.

If the user does not have a group and tries to create a node, you must display the group creation form with a message:

"You need to create a group to be able to create content"

dalra’s picture

Deleted

zenimagine’s picture

@dalra It would be nice to have an option to make it mandatory.

On my site, a user can not create a node if he does not have a group.

Maybe in the field parameter it would be interesting to add this option.

anruether’s picture

From what I understand, there is quite a bit of the functionality that is being discussed here in this patch: https://www.drupal.org/project/group/issues/2718195#comment-12869526 Marking the issue as related.

This patch introduces a pseudo field which makes it possible to:
- Show which group a node is in on node form and view
- Add/remove groups through the node form (either limited to a specific group type or any group)

Especially the add/remove functionality might not be obvious from the issue title...

jidrone’s picture

Status: Needs work » Needs review
StatusFileSize
new24.91 KB
new56.41 KB

Hi Everyone,

Finally I finished a patch with the field approach, I created a widget for the entity reference field called "Group Selector" and a Formatter called "Parent Group Entity".

When you initially configure the field is needed to synchronize it to add the values for existing group content, for that reason I created an option in the field to do that.
Sync Field

You only need to check it the first time, for that reason the default value is unchecked.

It's important to select the Group Content as referenced entity in the field to see this option.

I decided to continue this patch because the solution from #2718195: Add a computed field for entity's group(s), does not cover the purpose of this issue.

IMPORTANT: If you used the previous patch, first uninstall the gcontent module, before to apply this.

zenimagine’s picture

@jidrone Thank you, I will test the patch on Monday

jidrone’s picture

I forgot to mention that I needed this patch #2939432: Make sure path has a value before calling purge in pathauto_entity_delete() for pathauto.

zenimagine’s picture

@jidrone I applied the patch, but did not understand how it works.

There is no group field in the content.

jidrone’s picture

Hi @zenimagine,

This new patch works as a widget for an entity reference field, so the steps to make it work are the following:

  • Go to "Manage Fields" for the content type do you want to add in groups.
  • Add a new field of type Reference > Other.
  • For the option "Type of item to reference" select Content > Group Content.
  • The option "Allowed number of values" depends on your expected behaviour.
  • On the next screen select all the group content bundles needed in "REFERENCE TYPE", I'm planning to do an improvement to set them as default value.
  • Go to "Manage Form Display" and select the widget "Group Selector" for the field you just created.
  • To show the group in the node display, go to "Manage Display" and select "Parent Group" as format the field.
zenimagine’s picture

@jidrone I encounter some problem with the patch, when I edit my node, I have a php error :

Error: Call to undefined method Drupal\gcontent_field\Plugin\Field\FieldWidget\GroupSelectorWidget::buildSelectAddMode() in Drupal\gcontent_field\Plugin\Field\FieldWidget\GroupSelectorWidget->buildAddActions() (line 788 of /var/www/www-domaine-com/web/modules/contrib/group/modules/gcontent_field/src/Plugin/Field/FieldWidget/GroupSelectorWidget.php) #0 /var/www/www-domaine-com/web/modules/contrib/group/modules/gcontent_field/src/Plugin/Field/FieldWidget/GroupSelectorWidget.php(702): Drupal\gcontent_field\Plugin\Field\FieldWidget\GroupSelectorWidget->buildAddActions(Array, 'group_node:arti...') #1 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Field/WidgetBase.php(104): Drupal\gcontent_field\Plugin\Field\FieldWidget\GroupSelectorWidget->formMultipleElements(Object(Drupal\Core\Field\EntityReferenceFieldItemList), Array, Object(Drupal\Core\Form\FormState)) #2 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Field/FieldItemList.php(287): Drupal\Core\Field\WidgetBase->form(Object(Drupal\Core\Field\EntityReferenceFieldItemList), Array, Object(Drupal\Core\Form\FormState)) #3 /var/www/www-domaine-com/web/core/modules/field_ui/src/Form/FieldConfigEditForm.php(99): Drupal\Core\Field\FieldItemList->defaultValuesForm(Array, Object(Drupal\Core\Form\FormState)) #4 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Entity/EntityForm.php(117): Drupal\field_ui\Form\FieldConfigEditForm->form(Array, Object(Drupal\Core\Form\FormState)) #5 [internal function]: Drupal\Core\Entity\EntityForm->buildForm(Array, Object(Drupal\Core\Form\FormState)) #6 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Form/FormBuilder.php(518): call_user_func_array(Array, Array) #7 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Form/FormBuilder.php(275): Drupal\Core\Form\FormBuilder->retrieveForm('field_config_ed...', Object(Drupal\Core\Form\FormState)) #8 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Controller/FormController.php(93): Drupal\Core\Form\FormBuilder->buildForm('field_config_ed...', Object(Drupal\Core\Form\FormState)) #9 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch)) #10 /var/www/www-domaine-com/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array) #11 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #12 /var/www/www-domaine-com/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #13 /var/www/www-domaine-com/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) #14 /var/www/www-domaine-com/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #15 /var/www/www-domaine-com/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #16 /var/www/www-domaine-com/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #17 /var/www/www-domaine-com/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #18 /var/www/www-domaine-com/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #19 /var/www/www-domaine-com/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(78): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) #20 /var/www/www-domaine-com/web/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #21 /var/www/www-domaine-com/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\ban\BanMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #22 /var/www/www-domaine-com/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #23 /var/www/www-domaine-com/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #24 /var/www/www-domaine-com/web/core/lib/Drupal/Core/DrupalKernel.php(669): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #25 /var/www/www-domaine-com/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #26 {main}.

zenimagine’s picture

Will not it be simpler than the module created a lock field ?

Autocomplete works, but the selection list shows the problem above.

Autocomplete displays the relationship content. Groups must be displayed. The name of the relationship is truncated

zenimagine’s picture

@jidrone "Widget: select" does not work on my site.

"Widget: autocomplete" works, but it does not display the group name.
In the autocompletion list, there is the name of the group, but when selected, it displays the name of the relationship.
If I change my knot how to know the group ?

zenimagine’s picture

jidrone’s picture

Status: Needs review » Needs work

Hi @zenimagine,

Thank you for all your testing, I will do the following changes in next patch:

  • Fix select widget.
  • Show Group Name first instead of Group content type when relation is added.
zenimagine’s picture

@jidrone Can the sub module directly create a lock field during installation ?

zenimagine’s picture

@jidrone A feature could be very interesting:

If the user does not have a group, when they create a node they should display a message (you must create a group to publish content) and the group creation form.

jidrone’s picture

Here is the patch with the following fixes and improvements:

  • Fix select widget.
  • Show Group Name first instead of Group content type when relation is added.
  • Respect entity cardinality.
jidrone’s picture

Status: Needs work » Needs review

I'm analyzing the possibility to create groups, maybe it could be an improvement in the future if the maintainer thinks the patch is useful.

anruether’s picture

I'm analyzing the possibility to create groups, maybe it could be an improvement in the future if the maintainer thinks the patch is useful.

Depending on your use casees (you might have others than we have ;) you might find group_behavior useful. It adds a group on node creation for a given content type (via content plugins), there is also groupmediaplus to automatically add media to the nodes group. Sorry for misusing your issue queue, I just wanted to mention it ....

jidrone’s picture

Another small fix for the plugin entity cardinality.

zenimagine’s picture

@jidrone Should I uninstall the sub module before applying the patch?

zenimagine’s picture

@jidrone I uninstalled the sub module and reinstalled it again.

I did a quick test:

1) In "Manage View" node, the field does not list any rendered entities. View screenshots Capture d’écran du 2018-12-13 12-02-19.png and Capture d’écran du 2018-12-13 12-01-44.png

2) When the group is selected, the label of the field disappears. View screenshots Capture d’écran du 2018-12-13 11-51-08.png and Capture d’écran du 2018-12-13 11-51-25.png

3) Why not create a real selection list as in Drupal Commerce for the store selection for the product. Groups should be listed by type of group. View screenshots Capture d’écran du 2018-12-13 12-04-32.png

4) In the group name ' are replaced by '

jidrone’s picture

Hi @zenimagine,

I fixed the things in comment #39, except the 4 because I didn't understand, is not needed to reinstall the module.

zenimagine’s picture

@jidrone Thank you, it works much better.
In 4 I mean that ' are replaced by '

I will continue to test it, but is it essential to have the button "Add group"?
A simple pick list when the field and limited to a single pick will require less manipulation. See the screenshots, for example the "Language" field.

zenimagine’s picture

1) One choice

2) Many choices

zenimagine’s picture

One more thing, I have the module https://www.drupal.org/project/message
When I use the token of the group field to display a link to the parent group of the node, this displays the relationship entity with the node.

Normally I should have the name and link of the parent group

jidrone’s picture

Hi @zenimagine,

In this patch I fixed the ' replaced by '

The "Add Group" button is really needed for the ajax functionality in the field items and regarding the token you can follow this great article about how to do it https://www.flocondetoile.fr/blog/token-and-chained-entities-drupal-8

zenimagine’s picture

@jidrone 884/5000
Thanks for the patch, it works.
The character problem is fixed.
I managed to find the right token, with your link.

Just one or two things that may need to be reviewed:

1) in the screenshot Capture d’écran du 2018-12-14 19-53-27.png when I add a group to the content, this is well presented.

2) in the screenshot Capture d’écran du 2018 12 14 19 52 33.png when I change the group of a content, this is poorly presented. The design is not suitable for the smartphone, I think the "Edit" button and the title of the relationship should not be displayed.

3) since this sub-module manages the relations between the groups and the nodes directly on the editing page of the node. Why the module does not prohibit access to the page (this page may be of interest to the site administrator, but not to the group administrator) :
/group/ID/content
and the "Associate Content" and "Add Content" buttons on :
/group/ID/nodes

4) with you take a look at the demonstration of open social? try to add content, a selection list is available for groups. But I am not a programmer.

5) There are also chips that appear next to the button. I do not know if this is related to Bootstrap

geek-merlin’s picture

Status: Needs review » Needs work

Huh, we have 3 issues with roughly the same scope:
* (this one) #2813405: Add a field to view and edit content's groups
* #2718195: Add a computed field for entity's group(s)
* #2774533: Better UI for adding content to multiple groups

Let's try to sort this out and consolidate. I'll start with the easiest:
* #2774533: Better UI for adding content to multiple groups - this code looks like included in both other issues so tentatively closing as dup.
* (this one) #2813405: Add a field to view and edit content's groups - I did not test this patch, but code-wise it looks well elaborated. chapeau! alas, it suffers from a denormalized design to take a entityreference field and sync it to group relation.
* #2718195: Add a computed field for entity's group(s) - a computed field that has no storage and loads and stores from group relation.

I'd suggest to consolidate the patches by replacing this patch's field syncing with the other patches much cleaner computed field approach.
(Of course YMMV and we can query a maintainer verdict about that)

geek-merlin’s picture

Title: Adding Content Relationships Outside of Groups » Add a field to view and edit content's groups
jidrone’s picture

Hi @axel.rutz,

I didn't test the #2718195: Add a computed field for entity's group(s), does it allow to add the content to the group from the entities form?.

I'm asking because this patch allows all View, Add, Edit and Remove.

anruether’s picture

> I'm asking because this patch allows all View, Add, Edit and Remove.

Yes, it does. I mentioned that earlier. What exactly do you mean by edit? Do you mean the group relation? I'm not sure if this can/should be done in the field widget... Apart from that you can View, Add and Remove with the other patch.

jidrone’s picture

I'm testing #2718195: Add a computed field for entity's group(s), to see if we can replace the field syncing as @axel.rutz propose.

jidrone’s picture

Status: Needs work » Needs review
StatusFileSize
new57.67 KB

This new patch includes the suggestion from @axel.rutz, instead of syncing field storage, it creates a computed field called "Group content" ready to use on entities from Group Content Plugins.

Thanks @axel.rutz.

zenimagine’s picture

@jidrone Thank you, the sub module is already installed on my site. To update to the new patch, should you uninstall your module? Thank you

jidrone’s picture

Hi @zenimagine,

You don't need to uninstall, just rebuild cache and this time the field will appear automatically, so you don't need to create it.

zenimagine’s picture

@jidrone Currently I have created fields for the previous patch. It is no longer useful ?

jidrone’s picture

Hi @zenimagine,

They are no longer useful, because they depends on field storage and previous syncing functionality, I recommend you to use the new one.

zenimagine’s picture

@jidrone Thank you, the patch works. But I see 2 problems:

- the rendered entities of the group do not correspond to the displays of the group type.

- it is not possible to limit the relation to a single group (single selection).

zenimagine’s picture

@jidrone When I turn on the group in the node type view, it displays the name of the relationship. You must display the name of the group.

The field should also be required

zenimagine’s picture

StatusFileSize
new109.36 KB

If the field is not configurable, maybe the solution would be to add parameters for the group in edit the node type

jidrone’s picture

Hi @zenimagine,

I added those options to the widget, the default values are Multiple: Yes and Required No.

Regarding the view modes for the groups, the default formatter is rendered entity, but the entity type being referenced is the group content, to show the group you will need to select "Parent Group Entity" as formatter in Manage Display.

zenimagine’s picture

StatusFileSize
new125.58 KB

@jidrone Super thank you, it works. It misses the label of the field, once it is selected

Would it be possible to customize the label of the field "Group content" in the widget?

zenimagine’s picture

StatusFileSize
new127.04 KB

I think only the name of the group should be displayed. The name of the relationship of the content is not useful

zenimagine’s picture

StatusFileSize
new109.79 KB

The group field in the node edit form for the multivalue is more convenient in the patch below.

With your last patch and the changes you've made, maybe it's possible to create the same rendering for multiple values. As well as a simple list for a single value.

https://www.drupal.org/project/group/issues/2718195

jidrone’s picture

Hi @zenimagine,

The reason why I don't follow that approach is because in the patch you mentioned is only posible to reference the group, so is not possible to set any custom fields you have configured for the content plugin and other important case is for users is not possible to assign them a group role.

The field from this patch references the group content which makes more sense and also allow you to completely admin the group content relation, for this reason is needed the ajax behavior and the "Add to group" button.

jidrone’s picture

StatusFileSize
new56.68 KB

This patch fixes the field label hidden when group is selected and also removes the group content bundle label.

To replace the field label I think it can be done using hook_entity_bundle_field_info_alter, I also removed the inline_entity_form dependency because from patch in comment #22 it's not needed but I forgot to remove it.

zenimagine’s picture

StatusFileSize
new135.74 KB

@jidrone Thank you, the label is correctly displayed.

When I click on the "Remove" button, it is the name of the group content that appears in place of the group name.

I can no longer display the token with the "Message" module.

<a href='[message:field_node_reference:entity:group_content:entity:group:url]'>[message:field_node_reference:entity:group_content:entity:group:title]</a>

With the field created manually, it will work. Now the code above does not display the group.

jidrone’s picture

StatusFileSize
new56.05 KB

Hi @zemagine,

I fixed the name of the group when removing, but the token I think is related with #2794343: Programatically defined fields for custom content entities are not available as tokens in Pathauto from token module.

zenimagine’s picture

@jidrone Thank you, the name of the group is now fixed.

But the open problem for the chips, has been closed and does not fix the problem.

It would be nice to add a token to the module to display the parent group of a node.

Is it normal for the button to use ul and li ?

zenimagine’s picture

jidrone’s picture

Hi @zenimagine,

I added support for token and yes it is normal to see the button as ul and li because it is a dropbutton, in the admin theme it looks good, so you can check how the theme "Seven" does.

zenimagine’s picture

@jidrone Perfect, the token works. Regarding the chips on the buttons, I think there is a problem with the Bootstrap theme. This problem only appears with this module. On the rest of the site, the drop-down buttons are correctly displayed.

Here are some idea of ​​features to add:

- On the page "/admin/content" it would be nice if the module Group adds a column with the parent groups of the nodes. Mass operations could also be added "Add nodes to groups" and "Delete nodes from groups".

- When this sub module is installed, I think it should disable the page "/group/ID/content", which is very confusing for the user. On the "/group/ID/nodes" page, the "Add new content" and "Add existing content" buttons should also be disabled.

- A check should be made when the user creates a node. View a message, if it does not have a group yet "Before creating a content, you must create a group (group creation link)".

- The group content field is limited to groups created by the user, that's fine. But the site administrator should have access to the complete list of groups.

- Maybe this is a problem of my site, but the "Edit" button in the "Group Content" field on the node edit page does not work.

That's it for now. Thank you for your work.

zenimagine’s picture

Is it normal that the field is also on the user account ?

jidrone’s picture

Hi @zenimagine,

Here are my thoughts:

"/admin/content" column parent groups:
I think that is a great suggestion but it is out of the scope of this issue, I suggest to create a new issue for that.

Disable "/group/ID/content":
This field added by this patch should be an additional functionality, for that reason I don't like the idea to disable core functionalities of group module because both can coexist and can be useful depending of your site roles and group contents administration scenarios.

Group creation link:
I can add a link to create a group if the user has the permissions and there are no available groups.

Access to groups:
This module check the permissions of groups for all the operations and for the list of available groups, so the super admin user should be able to do anything, please check the group types permission and help me to test.

Edit button:
For me it works, maybe other users on this issue queue can test it.

Field on user entity type:
Yes it's ok to see the field on users, that is because this submodule detects all the fieldable entity types which have support for group module via GroupContentEnabler plugin type, the group module adds the "group_membership" for users (this patch allow to create users and add them to groups) and the gnode submodule adds the "group_node" for nodes.
It means if you or someone else add support to other fieldable entity type for group, then the field "group_content" will be available on the entity form.

jidrone’s picture

Issue summary: View changes
jonathanshaw’s picture

@jidrone The work you've done here on a computed reverse reference field, and especially on the corresponding widget, is great. I can see many use cases for this outside of group too. How much work do you think it would be to generalise it into its own contrib module that could be used with any entity reference field; the Group module could then have an optional dependency on this new contrib module.

maxilein’s picture

If you research this, please consider the functionality of the cer module.

jidrone’s picture

Hi @jonathanshaw,

I think the formatter I created in this patch is totally intended to be use with groups, then if the module proposed by @maxilein does not provide a generalized way to do this maybe we can help on that module or create a new contrib.

zenimagine’s picture

@jidrone Hi, when I try to add a group, it does not work and I have an error :

Emplacement https://www.domaine.com/fr/node/243/edit?_wrapper_format=drupal_ajax&aja...
Référent https://www.domaine.com/fr/node/243/edit

Error: Call to a member function getContentPlugin() on null in Drupal\gcontent_field\Plugin\Field\FieldWidget\GroupSelectorWidget->formMultipleElements() (line 711 of /var/www/www-domaine-com/web/modules/contrib/group/modules/gcontent_field/src/Plugin/Field/FieldWidget/GroupSelectorWidget.php) #0 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Field/WidgetBase.php(104): Drupal\gcontent_field\Plugin\Field\FieldWidget\GroupSelectorWidget->formMultipleElements(Object(Drupal\gcontent_field\Field\GcontentFieldItemList), Array, Object(Drupal\Core\Form\FormState)) #1 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php(171): Drupal\Core\Field\WidgetBase->form(Object(Drupal\gcontent_field\Field\GcontentFieldItemList), Array, Object(Drupal\Core\Form\FormState)) #2 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Entity/ContentEntityForm.php(125): Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm(Object(Drupal\node\Entity\Node), Array, Object(Drupal\Core\Form\FormState)) #3 /var/www/www-domaine-com/web/core/modules/node/src/NodeForm.php(115): Drupal\Core\Entity\ContentEntityForm->form(Array, Object(Drupal\Core\Form\FormState)) #4 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Entity/EntityForm.php(117): Drupal\node\NodeForm->form(Array, Object(Drupal\Core\Form\FormState)) #5 [internal function]: Drupal\Core\Entity\EntityForm->buildForm(Array, Object(Drupal\Core\Form\FormState)) #6 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Form/FormBuilder.php(518): call_user_func_array(Array, Array) #7 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Form/FormBuilder.php(368): Drupal\Core\Form\FormBuilder->retrieveForm('node_partenaire...', Object(Drupal\Core\Form\FormState)) #8 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Form/FormBuilder.php(625): Drupal\Core\Form\FormBuilder->rebuildForm('node_partenaire...', Object(Drupal\Core\Form\FormState), Array) #9 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Form/FormBuilder.php(318): Drupal\Core\Form\FormBuilder->processForm('node_partenaire...', Array, Object(Drupal\Core\Form\FormState)) #10 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Controller/FormController.php(93): Drupal\Core\Form\FormBuilder->buildForm('node_partenaire...', Object(Drupal\Core\Form\FormState)) #11 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch)) #12 /var/www/www-domaine-com/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array) #13 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #14 /var/www/www-domaine-com/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #15 /var/www/www-domaine-com/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) #16 /var/www/www-domaine-com/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #17 /var/www/www-domaine-com/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #18 /var/www/www-domaine-com/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #19 /var/www/www-domaine-com/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #20 /var/www/www-domaine-com/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #21 /var/www/www-domaine-com/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(78): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) #22 /var/www/www-domaine-com/web/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #23 /var/www/www-domaine-com/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\ban\BanMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #24 /var/www/www-domaine-com/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #25 /var/www/www-domaine-com/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #26 /var/www/www-domaine-com/web/core/lib/Drupal/Core/DrupalKernel.php(693): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #27 /var/www/www-domaine-com/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #28 {main}.

jidrone’s picture

Hi @zenimagine,

I was testing but I couldn't reproduce that error.

zenimagine’s picture

@jidrone This problem only appears with the site administrator. For the user to work

jidrone’s picture

I couldn't reproduce the error with different scenarios.
This patch only improves the access to field when editing own user account and the message when reached entity cardinality.

jidrone’s picture

StatusFileSize
new59.35 KB
new777 bytes

Small usability improvement, the relation field gets cleared after new relation is added.

jidrone’s picture

Issue summary: View changes
zenimagine’s picture

@jidrone Thank you, I tested the patch and I still have the same error. I do not know where it comes from.

zenimagine’s picture

@jidrone When I open the ajax link, I have the message below, but I do not understand what it means :

[{"command":"insert","method":"prepend","selector":null,"data":" \u003Cdiv role=\u0022contentinfo\u0022 aria-label=\u0022Error message\u0022 class=\u0022messages messages--error\u0022\u003E\n \u003Cdiv role=\u0022alert\u0022\u003E\n \u003Ch2 class=\u0022visually-hidden\u0022\u003EError message\u003C\/h2\u003E\n An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (24 MB) that this server supports.\n \u003C\/div\u003E\n \u003C\/div\u003E\n ","settings":null}]

zenimagine’s picture

@jidrone Have you tested the module with several types of groups?

With one type of group it works, but with the others, I have this error and nothing happens.

zenimagine’s picture

@jidrone I asked the question on stackexchange and a user replied :

In your gcontent_field module, you're calling ->getContentPlugin() in the Drupal\gcontent_field\Plugin\Field\FieldWidget\GroupSelectorWidget->formMultipleElements() method.

You're assuming that you're calling the method on an object, but for some reason, the object is not there so you're getting NULL. You should do a check on the object to see if the object is actually an object. Maybe, use is_a() or gettype() functions to confirm your variable type before calling the getContentPlugin() method? Or see why the object is not being passed to your method correctly?

jidrone’s picture

StatusFileSize
new59.33 KB
new881 bytes

Hi @zenimagine,

Try this small change.

zenimagine’s picture

@jidrone I will test that. Have you managed to reproduce the problem ?

zenimagine’s picture

@jidrone I applied the patch, but that does not solve the problem.

With one type of group it works, but not with the other type of group.

dww’s picture

Thanks for all the work here so far! This is getting close to a very useful feature.

In addition to the unresolved bug from #77 through #89, I'm setting to needs work for a few more things:

1. There's no obvious way to change the "Group content" label. Yes, I could form alter the widget and entity_view_alter to fix the display, but wow that's a lot of work. I know this is a "magic" field that appears automatically, but it'd be great if it also appeared on 'manage fields' in some way, at least to let you change the name/label.

Eventually it could support other goodies that normally appear at manage fields, like required, default value, etc., but that might get too complicated and should probably be a follow-up issue.

2. We should also consider if "Group content" makes sense as the default label for this, regardless of if you can easily customize it. It's really "Groups this content belongs to" or even just "Groups" (in the context of a field on site content). If I'm looking at, say, an event that can belong to multiple groups, the things this field shows me are the groups the event belongs to. The event is the "group content", and this field is really pointing to the groups themselves.

3. It'd be better if once you enable this, a site builder gets to turn it *on* on the 'Manage form display' page for any entity types that make sense, instead of having to manually turn it off everywhere it doesn't.

4. If I login as a group admin, the help text needs help:

Group admin adding content

Group content
No added yet to groups.
[ ]
Type a group
(Add to Group)

"Group content" should be configurable (see #1 above).

a. "No added yet to groups.:"

Should be: "Not yet added to groups." or even "Not in any groups."

b. "Type a group"

This is a (not very helpful) description, but the form element it describes has no label (making this an accessibility bug). I think there should be a "Group name" label, then you don't need the description at all. The call-to-action remains "Add to Group".

5. If you press "Add to Group" without typing a group name, nothing happens, no error or warning is generated.

6. If the content does not yet belong to any groups, and you type an invalid name and try to "Add to Group", the name is marked red, but there's no other error message:

 no error message.

We need to display the form validation error messages in this case.

7. If you successfully add the content to a group, then try again with something invalid, you now see an error message, but it's generic and not very user-facing-friendly:

 generic and cryptic error message.

There are no entities matching "dww".

Should be something like: There are no groups named "%group_name".

8. If I login as a user that belongs to a few groups, but doesn't have permission to post anything to those groups, and I try to create content that *could* be associated with a group (but not by me), I get the following error message:

Weird error message for group members (not admins) who can't add content to groups.

If the current user doesn't have permission to add content to a group, the widget should hide those aspects completely, and only show current group memberships in a read-only listing.

9. Configuring display is clumsy. If I use 'label', I get the label of the association between the content and each group. This always duplicates the name of the content itself, and as a site-builder or end user, it just seems like a bug. If I choose "entity ID" I see that they're unique entities, even though the labels are equivalent. If I use 'rendered entity' I get the full rendered entity of the association of the content and each group, again, totally useless for me to see as an end user. The only option that actually makes any sense here is "Parent group entity", but then I'm forced to use a view mode to render the full entity. At this point, I have to add a new 'Name-only' view mode of group entities, then come back to configure the display of every content type on my site to click a few different times on each of these 'Group content' field formatters. :(

I can't imagine a scenario where you want to see the group-association entities with this formatter. Why doesn't it immediately assume you're talking about the parent group, and then retain the options for label-only (with and without a link to the group entity itself), id, or a full rendered entity? Or if there's a reasonable use-case for seeing the group-content-association entities, make that the special case that requires more clicks.

10. It'd be great to have some functional tests for all these cases. Stretch goal. ;) I leave it to the maintainers to decide if this is a requirement.

jidrone’s picture

Status: Needs work » Needs review
StatusFileSize
new65.68 KB
new19.36 KB

Hi Everyone,

Here is the new patch with some improvements suggested in #90:

  1. Field label now is customizable from "admin/group/settings".
  2. Default field label now is "Groups".
  3. That is a good suggestion, I tried to do that following the right process, but it didn't work, maybe there is a core issue for base fields added via hook_entity_base_field_info or computed fields, I will need to investigate more.
  4. Added group field label and text improvements.
  5. Added validation when empty field, I suggest to enable Inline Form Errors module for better UX.
  6. Improved validation messages.
  7. I suggest to enable Inline Form Errors module for better UX.
  8. Improved message when user doesn't have permission.
  9. The field on this patch is referencing the group content entity instead of group, it is especially useful for example in user membership, because it gives the possibility to configure the group roles.
    Then you can set the formatter as referenced entity and show a summary of user membership.
    By default the field is hidden from display and with the mentioned scenario I think is better not to assume the field formatter as parent group
  10. Yes, maybe we will need some tests

Status: Needs review » Needs work
jidrone’s picture

Status: Needs work » Needs review

Moved to needs review, it didn't pass the PHP5 tests because it uses php ternary null coalescing added in PHP7, but I think it is not a blocker because php 5 support will end soon.

zenimagine’s picture

@jidrone thank you for this update.
However there is some detail to settle.

No label is set by default, so only the required field star appears if I do not customize the label.

I noticed that users tend to select a group and save the content without clicking the "Add a group" button. The content shows a wander in the form but it is not obvious to them.

balbuf’s picture

I am receiving the same error as @zenimagine in #77 with latest patch and as Administrator.

I would also echo @zenimagine's comment in #95 regarding the "Add to Group" button. Ideally, the groups would just be connected upon saving the actual piece of content, eliminating the extra step.

Thank you for your work on this @jidrone! I will see if I can dig in and contribute anything.

scotwith1t’s picture

I believe the reason for the "Add to Group" step is a data integrity issue: so that required fields aren't left empty on the Relationship entity. For instance, for Group Membership plugin you likely will have to fill out the Group Membership entity (group roles field to fill out, along with any other custom membership entity fields in order for the "groups to just be connected". I suppose if the 2-step wizard is disabled for a plugin, maybe then you could safely skip that step, since the configuration is such that this step is skipped when creating the Relationship entity directly (rather than via the related entity's form via this new field widget). Hope that makes sense...

balbuf’s picture

@scotself good point about having additional fields on the Relationship entity. I wasn't thinking about that because 1) I don't yet have any need to add fields on the Relationship entity, and 2) I can't get this patch to work to even see what the UX flow looks like in terms of filling such fields when adding new groups to a piece of content.

balbuf’s picture

I created a new patch based of the one in #45 here: https://www.drupal.org/project/group/issues/2718195#comment-12869526

What I liked about that code is that it inherently supports any display widgets that an EntityReference field supports, and it doesn't require the additional "Add to Group" step. (However, I hadn't considered the additional Relationship fields @scotself mentioned in #97 - I'm not sure how those would be handled.)

Anyway, I took that patch as a starting point and leveraged some of @jidrone's logic to restrict group relationship addition/removal based on the appropriate permissions. I also added logic such that the computed field is only added to content types that are enabled for one or more groups.

Perhaps this may be useful to someone!

Status: Needs review » Needs work
geek-merlin’s picture

So the current patch is #91 and #99 is a case study based on old #45? Wouldn't it be good to improve #91?

jidrone’s picture

Hi everyone, I will work on this again on next week.

zenimagine’s picture

@jidrone Maybe you could find help here https://www.drupal.org/project/gnode_field

dww’s picture

Re: @zenimagine #103: how could we possibly know? ;) There's no description on the project page. I cloned the repo and there's no README or anything. I looked in gnode_field_help() and found only this:

$output .= '<p>' . t('Functionality as it relates to groups on the site.')

I have no idea WTF that module is for. ;) Hah, just found #3033566: Hi, what is this module for ? ;)

Oh, at least gnode_field.info.yml has this:
description: Add groups directly from the node form.
Guess I should have looked there before hook_help. Oh well...

Anyway, yeah, it seems quite overlapping. Would be great to merge efforts if possible, get this functionality working here and deprecate that project so we don't end up with splintered/forked modules for the same feature.

Thanks for the pointer!
-Derek

balbuf’s picture

@axel.rutz #2718195-45: Add a computed field for entity's group(s) was a better starting point for me because it worked / produced no errors, allowed me to use any entity reference widget (in my case I want to use a checkbox list), eliminated the extra "Add to Group" step, and was comparatively simpler code. That may be an older patch and a closed issue, but it's still valuable work.

Per the issue of a group content entity allowing additional fields, I feel like this would be best handled with the optional 2-step wizard. On the content edit screen you'd select the groups you want, then, based on the selected groups, show the group content form for each selected group (IF the wizard is enabled - for instances where the group content entity has no additional fields, you just disable the wizard to eliminate this step). Not sure how your patch handles it @jidrone, but I think this would be the most flexible and ideal UX.

dalra’s picture

@balbuf

#2718195-45: Add a computed field for entity's group(s) was a better starting point for me because it worked / produced no errors, allowed me to use any entity reference widget (in my case I want to use a checkbox list), eliminated the extra "Add to Group" step, and was comparatively simpler code. That may be an older patch and a closed issue, but it's still valuable work.

Would your patch allow for a radio button list of groups to be displayed on an article?
In the article node, I would like to allow users to choose a group from a radio list and click save.
This would add an article to a group with just 2 clicks.

Also, I would like the content to be in just one group (Public or Private).
If the content is already in the Public group and the user adds it to the Private group, the content needs to removed from the Public group.

Would that be possible with your patch?
Thank you

dan_metille’s picture

I have applied patch #91, but cannot enable 'gcontent_field' module, as it is complaining about my Entity module version:

Entity (>=8.x-1.0-rc1) (incompatible with version )

I have tried with both 1.0-rc1 and 1.0-dev version of Entity, without success.

EDIT: I could enable the module via Drupal Consol.

geek-merlin’s picture

#107:
> Entity (>=8.x-1.0-rc1)

i do not see that line in the patch. Alas, if it's in a info.yml file, it should read:

> Entity (>=1.0-rc1)

anruether’s picture

Testing #91, some remarks:
1. The Group selection on node/add forms needs the "Relationship: Add entity relation" permission, although the "Entity: Add content entities" permission should suffice
2. If the user does not have the permission to remove a relation, he cannot change the group again. This seems to be a bit strict, since the node does not exists yet
3. It only works with the default group type, not with any custom group type. There I'm getting a similar error as #77:

Error: Call to a member function getContentPlugin() on null in Drupal\group\Entity\GroupContent->getContentPlugin() (line 102 of /var/www/html/web/modules/contrib/group/src/Entity/GroupContent.php)

#0 /var/www/html/web/modules/contrib/group/modules/gcontent_field/src/Plugin/Field/FieldWidget/GroupSelectorWidget.php(1122): Drupal\group\Entity\GroupContent->getContentPlugin()
#1 /var/www/html/web/modules/contrib/group/modules/gcontent_field/src/Plugin/Field/FieldWidget/GroupSelectorWidget.php(703): Drupal\gcontent_field\Plugin\Field\FieldWidget\GroupSelectorWidget->getAllowedGroups(Array, 'group_node:arti...', Array)
#2 /var/www/html/web/core/lib/Drupal/Core/Field/WidgetBase.php(104): Drupal\gcontent_field\Plugin\Field\FieldWidget\GroupSelectorWidget->formMultipleElements(Object(Drupal\gcontent_field\Field\GcontentFieldItemList), Array, Object(Drupal\Core\Form\FormState))
#3 /var/www/html/web/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php(171): Drupal\Core\Field\WidgetBase->form(Object(Drupal\gcontent_field\Field\GcontentFieldItemList), Array, Object(Drupal\Core\Form\FormState))
#4 /var/www/html/web/core/lib/Drupal/Core/Entity/ContentEntityForm.php(125): Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm(Object(Drupal\node\Entity\Node), Array, Object(Drupal\Core\Form\FormState))
#5 /var/www/html/web/core/modules/node/src/NodeForm.php(115): Drupal\Core\Entity\ContentEntityForm->form(Array, Object(Drupal\Core\Form\FormState))
esolitos’s picture

Hello, I've found the patch from https://www.drupal.org/project/group/issues/2718195 in Open Social, now I need to implement a similar thing and I wonder: what patch should I use here to be "future=proof"?

I see two completely different approaches and I fear that choosing the wrong one will cause issues on the long run, so just wondering what's the general opinion here for the future.

dww’s picture

We've now got 3 possible options:

  1. #91
  2. #2718195-45: Add a computed field for entity's group(s)
  3. https://www.drupal.org/project/gnode_field

Fun. ;)

  • I reviewed / tested #87 (see #90), but I haven't reviewed #91 yet.
  • Only briefly looked at #2718195.
  • Barely looked at gnode_field.

I can't give any recommendation on the "future-proof" choice. :(

Would love to get everyone into a shared conversation about it. Not sure if this issue is the best place for that. #d8-group in Drupal Slack? DrupalCon bof with a remote option (Zoom, Slack, etc?). I'm not yet clear who "everyone" means. :/

@kristiaanvandeneynde group maintainer
@scottalan from gnode_field
@jidrone from #91
@joachim, @axel.rutz, @modestmoes, @recrit, @realityloop, @adammalone et al from #2718195
... ?

Thoughts on how to proceed?

Thanks!
-Derek

p.s. Opened #3045046: Consider merging this into group module? to ping @alanscott as the maintainer of gnode_field.

geek-merlin’s picture

@dww,

Derek, thanks for bringing this up so we can sort out this whole mess.

* Looked into https://www.drupal.org/project/gnode_field. That module uses a form_alter approach that i'd strongly discourage.
* My comments from #46 still apply so i'd strongly advise going with #91 and not the closed issue

Also, until drupal.org supports a branch-per-issue, someone(tm) might open a sandbox and invite everyone here.
With a complex patch like this one this might really help. (Just my 2 cents, i don't think i can put much bandwidth in here.)

joachim’s picture

+++ b/modules/gcontent_field/gcontent_field.module
@@ -0,0 +1,77 @@
+  if ($entity_types = gcontent_field_get_entity_types()) {

Isn't this going to be circular?

geek-merlin’s picture

Clarifiing current patch (which the last question correctly refers to).

scotwith1t’s picture

FWIW, we're using #91 in a project for the last couple months and haven't had any issues thus far.

geek-merlin’s picture

Status: Needs work » Reviewed & tested by the community

> FWIW, we're using #91 in a project for the last couple months and haven't had any issues thus far.

OK, setting this to RTBC to bug @kristiaanvandeneynde and get his review on this.
It would be really nice if we get this in soon and move forther improvements into a followup.

anruether’s picture

Status: Reviewed & tested by the community » Needs work

Setting back to Needs work, for #91 we have some comments in #90 which have not been addressed and #109:

Does not work for any other group type than the default group type mentioned in #85 and #109

Some points from #90 not yet addressed, such as

9. Configuring display is clumsy. [...] The only option that actually makes any sense here is "Parent group entity", but then I'm forced to use a view mode to render the full entity. At this point, I have to add a new 'Name-only' view mode of group entities, then come back to configure the display of every content type on my site to click a few different times on each of these 'Group content' field formatters. :(

I can't imagine a scenario where you want to see the group-association entities with this formatter. Why doesn't it immediately assume you're talking about the parent group, and then retain the options for label-only (with and without a link to the group entity itself), id, or a full rendered entity? Or if there's a reasonable use-case for seeing the group-content-association entities, make that the special case that requires more clicks.

Please see #90 (#91 for what has been taken care of) and #109

Also, I would add, that the form widget is also clumsy and missleading. On default autocomplete is enabled which let's you select a list of all content. The custom widget "Group Selector" is what you want. I hoped there is a more standard way to use existing widgets and formatters...

dww’s picture

Glad to see this moving forward. Yes, needs work. :) I started reviewing #91. Agreed that there are still a number of items from #90 not yet addressed. Also found these:

  1. --- /dev/null
    +++ b/modules/gcontent_field/config/install/gcontent_field.settings.yml
    
    +++ b/modules/gcontent_field/config/install/gcontent_field.settings.yml
    @@ -0,0 +1,2 @@
    
    @@ -0,0 +1,2 @@
    +entity_field_label:
    +  user: 'Group Memberships'
    \ No newline at end of file
    

    No newline

  2. +++ b/modules/gcontent_field/gcontent_field.info.yml
    @@ -0,0 +1,8 @@
    +description: 'Provide a new field which allows you to add group content from entity form'
    

    A) 'Defines a group content field type.'

    - Needs a period.
    - Simpler language more in line with core field types (image, text, etc).

    Or:

    B) 'Defines a group content relationship field type.'

    or very wordy, and referring to things we don't normally want to say in the user-facing text like "entity", but even more descriptive:

    C) 'Defines a field type to associate content with groups directly on the entity form.'

    ?

  3. +++ b/modules/gcontent_field/gcontent_field.info.yml
    @@ -0,0 +1,8 @@
    +version: 1.0
    

    This shouldn't be here, and will be added by d.o during packaging.

  4. +++ b/modules/gcontent_field/gcontent_field.libraries.yml
    @@ -0,0 +1,12 @@
    \ No newline at end of file
    

    And here

  5. +++ b/modules/gcontent_field/gcontent_field.module
    @@ -0,0 +1,77 @@
    + * Get entities where the field should be added.
    

    Maybe:

    "Get entities that should have a group content field."
    ?

  6. +++ b/modules/gcontent_field/gcontent_field.module
    @@ -0,0 +1,77 @@
    +    // Check if fields can be attached to the entity type.
    +    if ($entity_type_definition->get('field_ui_base_route')) {
    

    This seems like a weird way to test if the entity type in question is field-able. There must be a cleaner way to to this that doesn't depend on field_ui. Can't we test if something implements a certain interface, instead?

  7. +++ b/modules/gcontent_field/gcontent_field.module
    @@ -0,0 +1,77 @@
    +      $entity_types[$plugin_definition['entity_type_id']] = (string) $entity_type_definition->getLabel();
    

    Can we be more flexible here and honor a config setting or something to make this field opt-in instead of opt-out? Basically #90.3 (I think).

  8. +++ b/modules/gcontent_field/src/Element/GroupAutocomplete.php
    @@ -0,0 +1,57 @@
    + * Provides an group autocomplete form element.
    

    s/an/a

  9. +++ b/modules/gcontent_field/src/Element/GroupAutocomplete.php
    @@ -0,0 +1,57 @@
    +      $form_state->setError($element, t('Many groups are called %value. Specify the one you want by appending the id in parentheses, like "@value (@id)".', $params));
    

    Could shorten the text to:
    'Many groups are called %value. Pick one by appending the ID in parentheses, like "@value (@id)".'

  10. +++ b/modules/gcontent_field/src/Element/GroupAutocomplete.php
    @@ -0,0 +1,57 @@
    +      // More helpful error if there are only a few matching groups.
    +      $multiples = [];
    +      foreach ($groups as $id => $name) {
    +        $multiples[] = $name . ' (' . $id . ')';
    +      }
    +      $params['@id'] = $id;
    +      $form_state->setError($element, t('Multiple groups match this reference; "%multiple". Specify the one you want by appending the id in parentheses, like "@value (@id)".', ['%multiple' => implode('", "', $multiples)] + $params));
    +    }
    

    Nice touch with the error message here!

    However, it's more wordy than needed. Could be:

    'Multiple groups match: "%multiple". Pick one by appending the ID in parentheses, like "@value (@id)".'

  11. +++ b/modules/gcontent_field/src/Element/GroupAutocomplete.php
    --- /dev/null
    +++ b/modules/gcontent_field/src/Field/GcontentFieldItemList.php
    

    Stopping review here for now...

No time for further review.

It does seem like a shared branch somewhere in a sandbox of some sort could be helpful. d.o sandbox? GitLab? GitHub? Thoughts?

Thanks!
-Derek

dww’s picture

I created a d.o sandbox:

https://www.drupal.org/sandbox/dww/3045926

Clone of group module's 8.x-1.x branch.

I pushed a 2813405-group-content-field branch with #91 from here as commit c34f0ed.

Also pushed commit 6356f92 to fix #118 except points 6 and 7.

I added @jidrone, @axel.rutz, @joachim as co-maintainers. If anyone else wants access, please let me know.

Can we concentrate our efforts there to get this actually RTBC?

Thanks!
-Derek

geek-merlin’s picture

> I created a d.o sandbox:

❤ to work with you!

jidrone’s picture

Great, I will check this as soon as I can.

jidrone’s picture

Addressed all things on #109 and the point 6 of #118

dww’s picture

Status: Needs work » Needs review
StatusFileSize
new66.8 KB
new8.77 KB

Whoops, #122 is empty. But based on the sandbox project, I think this is what @jidrone meant to upload. I haven't reviewed or tested it, but it's got some commits from both me and @jidrone in it. ;) Interdiff relative to #91 attached.

Still needs work for more from #90, but calling this NR to see what the testbot and others think.

jidrone’s picture

Here is the new patch with 118.6 resolved, maybe I didn't pushed to sandbox before I created the patch.

Regarding the 118.7, related to 90.3, I wrote in 91 that I did the right code based on Drupal documentation but it was setting the field visible by default anyway. But after my latest tests it is working as expected and now the field should be configured in "Manage form display" to appear.

I someone else can test it, then we can say all issues from 90 and 118 are resolved.

catch’s picture

Just a note I'll be testing the latest patch for a client project over the next week or so, was thinking of creating a computed field to do this then fortunately found this issue first.

dww’s picture

@catch: Great! I made you co-maintainer on https://www.drupal.org/sandbox/dww/3045926 if you want to push any commits there.

I'll also be doing another round of review + testing on this for a project in the next few days. Hopefully we can coordinate any fixes and avoid duplicating any work. Here or #d8-group in Slack. I'm not at DrupalCon, sadly.

Thanks!
-Derek

catch’s picture

StatusFileSize
new914 bytes

Minor, but there's a null coalesce operator in gcontent_field.module which means a syntax error on PHP 5.6. Core's about to drop support for PHP 5.6 with 8.7.x but it'll still be supported by 8.6.0 a bit longer.

catch’s picture

StatusFileSize
new3.6 KB

Three more.

jidrone’s picture

Drupal 8.6 will still support PHP 5.6, but that version of PHP is an unsupported version by the PHP maintainers and for that reason most of the hosting providers already support PHP 7, so I think we don't need to downgrade the code, but if other users agree with you we can change it.

jidrone’s picture

Hi Everyone, did someone has time to test this patch with the latest improvements?

esolitos’s picture

Status: Needs review » Reviewed & tested by the community

I've been using patch from #124 for a while now, not in prod but on a quite complex site under heavy development, no big issue encountered.

scotwith1t’s picture

Same as @esolitos, we've not launched the project, but it's quite complex and we've had no issues with this patch while building out the client's product.

zenimagine’s picture

@jidrone Hi, I currently have the patch 91. Can I update with patch 124 or do I have to uninstall the sub module to update ? Thank you

zenimagine’s picture

@Jidrone I applied patch 124 and the group is not added to the node.

If I select a group and click on added, the addition form disappears and the group is not added.

zenimagine’s picture

zenimagine’s picture

If I try to save the node, I have a PHP error :

Drupal\Component\Plugin\Exception\PluginNotFoundException : The "entity:group_content:administrateur-group_node-partenaire" plugin does not exist. Valid plugin IDs for Drupal\Core\TypedData\TypedDataManager are: formatted_price, duration, entity_revision_reference, entity_revision, entity_revision:advancedqueue_queue, entity_revision:block, entity_revision:block_content, entity_revision:block_content:basic, entity_revision:block_content_type, entity_revision:comment, entity_revision:comment:annonce, entity_revision:comment:article, entity_revision:comment:demande, entity_revision:comment:discussion, entity_revision:comment:evenement, entity_revision:comment:itineraire, entity_revision:comment:produit, entity_revision:comment:recette, entity_revision:comment:service, entity_revision:comment_type, entity_revision:commerce_checkout_flow, entity_revision:commerce_log, entity_revision:commerce_order_item_type, entity_revision:commerce_order, entity_revision:commerce_order:default, entity_revision:commerce_order:produit, entity_revision:commerce_order:recurring, entity_revision:commerce_order:service, entity_revision:commerce_order_item, entity_revision:commerce_order_item:default, entity_revision:commerce_order_item:produit, entity_revision:commerce_order_item:recurring_product_variation, entity_revision:commerce_order_item:recurring_standalone, entity_revision:commerce_order_item:service, entity_revision:commerce_order_type, entity_revision:commerce_payment, entity_revision:commerce_payment:payment_default, entity_revision:commerce_payment:payment_manual, entity_revision:commerce_payment_method, entity_revision:commerce_payment_method:paypal, entity_revision:commerce_payment_method:credit_card, entity_revision:commerce_payment_gateway, entity_revision:commerce_currency, entity_revision:commerce_pricelist, entity_revision:commerce_pricelist:commerce_product_variation, entity_revision:commerce_pricelist_item, entity_revision:commerce_pricelist_item:commerce_product_variation, entity_revision:commerce_product_variation_type, entity_revision:commerce_product_variation, entity_revision:commerce_product_variation:default, entity_revision:commerce_product_variation:produit, entity_revision:commerce_product_variation:service, entity_revision:commerce_product_attribute, entity_revision:commerce_product, entity_revision:commerce_product:default, entity_revision:commerce_product:produit, entity_revision:commerce_product:service, entity_revision:commerce_product_type, entity_revision:commerce_product_attribute_value, entity_revision:commerce_product_attribute_value:couleur, entity_revision:commerce_product_attribute_value:masse, entity_revision:commerce_product_attribute_value:taille, entity_revision:commerce_product_attribute_value:temps, entity_revision:commerce_product_attribute_value:volume, entity_revision:commerce_promotion_coupon, entity_revision:commerce_promotion, entity_revision:commerce_subscription, entity_revision:commerce_subscription:standalone, entity_revision:commerce_subscription:product_variation, entity_revision:commerce_billing_schedule, entity_revision:commerce_order_report, entity_revision:commerce_order_report:order_report, entity_revision:commerce_order_report:order_items_report, entity_revision:commerce_order_report:tax_report, entity_revision:commerce_order_report:promotion_report, entity_revision:commerce_shipment_type, entity_revision:commerce_shipping_method, entity_revision:commerce_package_type, entity_revision:commerce_shipment, entity_revision:commerce_shipment:default, entity_revision:commerce_store, entity_revision:commerce_store:online, entity_revision:commerce_store:personnel, entity_revision:commerce_store:professionnel, entity_revision:commerce_store_type, entity_revision:commerce_tax_type, entity_revision:contact_form, entity_revision:contact_message, entity_revision:contact_message:feedback, entity_revision:contact_message:personal, entity_revision:content_moderation_state, entity_revision:crop_type, entity_revision:crop, entity_revision:crop:1_1, entity_revision:crop:2_1, entity_revision:crop:3_1, entity_revision:crop:3_2, entity_revision:crop:a4, entity_revision:editor, entity_revision:entity_legal_document_acceptance, entity_revision:entity_legal_document, entity_revision:entity_legal_document_version, entity_revision:entity_legal_document_version:cgu, entity_revision:entity_legal_document_version:mentions_legales, entity_revision:entity_legal_document_version:politique_de_confidentialite, entity_revision:field_config, entity_revision:field_storage_config, entity_revision:field_validation_rule_set, entity_revision:file, entity_revision:filter_format, entity_revision:flag, entity_revision:flagging, entity_revision:flagging:like_group, entity_revision:flagging:like_node, entity_revision:flagging:like_product, entity_revision:flagging:like_store, entity_revision:flagging:report_comment, entity_revision:flagging:report_group, entity_revision:flagging:report_node, entity_revision:flagging:report_private_message, entity_revision:flagging:report_product, entity_revision:flagging:report_profile, entity_revision:flagging:report_store, entity_revision:flagging:report_user, entity_revision:group_role, entity_revision:group_type, entity_revision:group, entity_revision:group:administrateur, entity_revision:group:personnel, entity_revision:group:professionnel, entity_revision:group_content, entity_revision:group_content:administrateur-group_membership, entity_revision:group_content:administrateur-group_node-guide, entity_revision:group_content:group_content_type_019ce60735906, entity_revision:group_content:group_content_type_0a627b6b58289, entity_revision:group_content:group_content_type_28f8a8dbd2f8b, entity_revision:group_content:group_content_type_9307df917f9ab, entity_revision:group_content:group_content_type_b1946b84b0196, entity_revision:group_content:group_content_type_ec36c5a835021, entity_revision:group_content:group_content_type_fa2db4a50c8e0, entity_revision:group_content:personnel-group_membership, entity_revision:group_content:personnel-group_node-annonce, entity_revision:group_content:personnel-group_node-article, entity_revision:group_content:personnel-group_node-discussion, entity_revision:group_content:personnel-group_node-evenement, entity_revision:group_content:personnel-group_node-itineraire, entity_revision:group_content:personnel-group_node-recette, entity_revision:group_content:professionnel-group_membership, entity_revision:group_content:professionnel-group_node-annonce, entity_revision:group_content:professionnel-group_node-article, entity_revision:group_content:professionnel-group_node-recette, entity_revision:group_content_type, entity_revision:image_style, entity_revision:language_content_settings, entity_revision:configurable_language, entity_revision:media, entity_revision:media:audio, entity_revision:media:file, entity_revision:media:image, entity_revision:media:remote_video, entity_revision:media:video, entity_revision:media_type, entity_revision:message_template, entity_revision:message, entity_revision:message:mas_create_comment, entity_revision:message:mas_create_group, entity_revision:message:mas_create_node, entity_revision:message:mas_create_product, entity_revision:message:mas_create_store, entity_revision:message:mas_user_register, entity_revision:message:notify, entity_revision:message:private_message_notification, entity_revision:metatag_defaults, entity_revision:node_type, entity_revision:node, entity_revision:node:annonce, entity_revision:node:article, entity_revision:node:demande, entity_revision:node:discussion, entity_revision:node:evenement, entity_revision:node:guide, entity_revision:node:itineraire, entity_revision:node:page, entity_revision:node:partenaire, entity_revision:node:question, entity_revision:node:recette, entity_revision:node:tutoriel, entity_revision:pathauto_pattern, entity_revision:private_message, entity_revision:pm_thread_delete_time, entity_revision:private_message_thread, entity_revision:pm_thread_access_time, entity_revision:profile_type, entity_revision:profile, entity_revision:profile:customer, entity_revision:redirect, entity_revision:responsive_image_style, entity_revision:search_api_index, entity_revision:search_api_server, entity_revision:search_api_task, entity_revision:search_api_autocomplete_search, entity_revision:solr_field_type, entity_revision:menu, entity_revision:action, entity_revision:taxonomy_term, entity_revision:taxonomy_term:annonce_categories, entity_revision:taxonomy_term:annonce_tags, entity_revision:taxonomy_term:article_tags, entity_revision:taxonomy_term:boutique_tags, entity_revision:taxonomy_term:discussion_tags, entity_revision:taxonomy_term:evenement_tags, entity_revision:taxonomy_term:groupe_tags, entity_revision:taxonomy_term:itineraire_tags, entity_revision:taxonomy_term:page_tags, entity_revision:taxonomy_term:produit_labels, entity_revision:taxonomy_term:produit_tags, entity_revision:taxonomy_term:profil_sexe, entity_revision:taxonomy_term:question_categories, entity_revision:taxonomy_term:recette_categories, entity_revision:taxonomy_term:recette_ingredients, entity_revision:taxonomy_term:recette_niveaux, entity_revision:taxonomy_term:recette_tags, entity_revision:taxonomy_term:recette_types, entity_revision:taxonomy_term:service_tags, entity_revision:taxonomy_vocabulary, entity_revision:tour, entity_revision:user, entity_revision:user_role, entity_revision:webform, entity_revision:webform_submission, entity_revision:webform_submission:concours_fevrier_2018, entity_revision:webform_submission:invitation, entity_revision:webform_submission:mode_de_livraison, entity_revision:webform_submission:passerelle_de_paiement, entity_revision:webform_submission:supprimer_la_boutique, entity_revision:webform_submission:supprimer_le_compte, entity_revision:webform_submission:supprimer_le_groupe, entity_revision:webform_options, entity_revision:workflow, entity_revision:menu_link_content, entity_revision:view, entity_revision:paragraph, entity_revision:paragraph:evenement_programmations, entity_revision:paragraph:itineraire_poi, entity_revision:paragraph:recette_ingredients, entity_revision:paragraph:recette_instructions, entity_revision:paragraphs_type, entity_revision:entity_form_display, entity_revision:entity_view_display, entity_revision:entity_form_mode, entity_revision:entity_view_mode, entity_revision:date_format, entity_revision:base_field_override, filter_format, metatag, search_api_html, search_api_text, solr_document, solr_field, entity, entity:advancedqueue_queue, entity:block, entity:block_content, entity:block_content:basic, entity:block_content_type, entity:comment, entity:comment:annonce, entity:comment:article, entity:comment:demande, entity:comment:discussion, entity:comment:evenement, entity:comment:itineraire, entity:comment:produit, entity:comment:recette, entity:comment:service, entity:comment_type, entity:commerce_checkout_flow, entity:commerce_log, entity:commerce_order_item_type, entity:commerce_order, entity:commerce_order:default, entity:commerce_order:produit, entity:commerce_order:recurring, entity:commerce_order:service, entity:commerce_order_item, entity:commerce_order_item:default, entity:commerce_order_item:produit, entity:commerce_order_item:recurring_product_variation, entity:commerce_order_item:recurring_standalone, entity:commerce_order_item:service, entity:commerce_order_type, entity:commerce_payment, entity:commerce_payment:payment_default, entity:commerce_payment:payment_manual, entity:commerce_payment_method, entity:commerce_payment_method:paypal, entity:commerce_payment_method:credit_card, entity:commerce_payment_gateway, entity:commerce_currency, entity:commerce_pricelist, entity:commerce_pricelist:commerce_product_variation, entity:commerce_pricelist_item, entity:commerce_pricelist_item:commerce_product_variation, entity:commerce_product_variation_type, entity:commerce_product_variation, entity:commerce_product_variation:default, entity:commerce_product_variation:produit, entity:commerce_product_variation:service, entity:commerce_product_attribute, entity:commerce_product, entity:commerce_product:default, entity:commerce_product:produit, entity:commerce_product:service, entity:commerce_product_type, entity:commerce_product_attribute_value, entity:commerce_product_attribute_value:couleur, entity:commerce_product_attribute_value:masse, entity:commerce_product_attribute_value:taille, entity:commerce_product_attribute_value:temps, entity:commerce_product_attribute_value:volume, entity:commerce_promotion_coupon, entity:commerce_promotion, entity:commerce_subscription, entity:commerce_subscription:standalone, entity:commerce_subscription:product_variation, entity:commerce_billing_schedule, entity:commerce_order_report, entity:commerce_order_report:order_report, entity:commerce_order_report:order_items_report, entity:commerce_order_report:tax_report, entity:commerce_order_report:promotion_report, entity:commerce_shipment_type, entity:commerce_shipping_method, entity:commerce_package_type, entity:commerce_shipment, entity:commerce_shipment:default, entity:commerce_store, entity:commerce_store:online, entity:commerce_store:personnel, entity:commerce_store:professionnel, entity:commerce_store_type, entity:commerce_tax_type, entity:contact_form, entity:contact_message, entity:contact_message:feedback, entity:contact_message:personal, entity:content_moderation_state, entity:crop_type, entity:crop, entity:crop:1_1, entity:crop:2_1, entity:crop:3_1, entity:crop:3_2, entity:crop:a4, entity:editor, entity:entity_legal_document_acceptance, entity:entity_legal_document, entity:entity_legal_document_version, entity:entity_legal_document_version:cgu, entity:entity_legal_document_version:mentions_legales, entity:entity_legal_document_version:politique_de_confidentialite, entity:field_config, entity:field_storage_config, entity:field_validation_rule_set, entity:file, entity:filter_format, entity:flag, entity:flagging, entity:flagging:like_group, entity:flagging:like_node, entity:flagging:like_product, entity:flagging:like_store, entity:flagging:report_comment, entity:flagging:report_group, entity:flagging:report_node, entity:flagging:report_private_message, entity:flagging:report_product, entity:flagging:report_profile, entity:flagging:report_store, entity:flagging:report_user, entity:group_role, entity:group_type, entity:group, entity:group:administrateur, entity:group:personnel, entity:group:professionnel, entity:group_content, entity:group_content:administrateur-group_membership, entity:group_content:administrateur-group_node-guide, entity:group_content:group_content_type_019ce60735906, entity:group_content:group_content_type_0a627b6b58289, entity:group_content:group_content_type_28f8a8dbd2f8b, entity:group_content:group_content_type_9307df917f9ab, entity:group_content:group_content_type_b1946b84b0196, entity:group_content:group_content_type_ec36c5a835021, entity:group_content:group_content_type_fa2db4a50c8e0, entity:group_content:personnel-group_membership, entity:group_content:personnel-group_node-annonce, entity:group_content:personnel-group_node-article, entity:group_content:personnel-group_node-discussion, entity:group_content:personnel-group_node-evenement, entity:group_content:personnel-group_node-itineraire, entity:group_content:personnel-group_node-recette, entity:group_content:professionnel-group_membership, entity:group_content:professionnel-group_node-annonce, entity:group_content:professionnel-group_node-article, entity:group_content:professionnel-group_node-recette, entity:group_content_type, entity:image_style, entity:language_content_settings, entity:configurable_language, entity:media, entity:media:audio, entity:media:file, entity:media:image, entity:media:remote_video, entity:media:video, entity:media_type, entity:message_template, entity:message, entity:message:mas_create_comment, entity:message:mas_create_group, entity:message:mas_create_node, entity:message:mas_create_product, entity:message:mas_create_store, entity:message:mas_user_register, entity:message:notify, entity:message:private_message_notification, entity:metatag_defaults, entity:node_type, entity:node, entity:node:annonce, entity:node:article, entity:node:demande, entity:node:discussion, entity:node:evenement, entity:node:guide, entity:node:itineraire, entity:node:page, entity:node:partenaire, entity:node:question, entity:node:recette, entity:node:tutoriel, entity:pathauto_pattern, entity:private_message, entity:pm_thread_delete_time, entity:private_message_thread, entity:pm_thread_access_time, entity:profile_type, entity:profile, entity:profile:customer, entity:redirect, entity:responsive_image_style, entity:search_api_index, entity:search_api_server, entity:search_api_task, entity:search_api_autocomplete_search, entity:solr_field_type, entity:menu, entity:action, entity:taxonomy_term, entity:taxonomy_term:annonce_categories, entity:taxonomy_term:annonce_tags, entity:taxonomy_term:article_tags, entity:taxonomy_term:boutique_tags, entity:taxonomy_term:discussion_tags, entity:taxonomy_term:evenement_tags, entity:taxonomy_term:groupe_tags, entity:taxonomy_term:itineraire_tags, entity:taxonomy_term:page_tags, entity:taxonomy_term:produit_labels, entity:taxonomy_term:produit_tags, entity:taxonomy_term:profil_sexe, entity:taxonomy_term:question_categories, entity:taxonomy_term:recette_categories, entity:taxonomy_term:recette_ingredients, entity:taxonomy_term:recette_niveaux, entity:taxonomy_term:recette_tags, entity:taxonomy_term:recette_types, entity:taxonomy_term:service_tags, entity:taxonomy_vocabulary, entity:tour, entity:user, entity:user_role, entity:webform, entity:webform_submission, entity:webform_submission:concours_fevrier_2018, entity:webform_submission:invitation, entity:webform_submission:mode_de_livraison, entity:webform_submission:passerelle_de_paiement, entity:webform_submission:supprimer_la_boutique, entity:webform_submission:supprimer_le_compte, entity:webform_submission:supprimer_le_groupe, entity:webform_options, entity:workflow, entity:menu_link_content, entity:view, entity:paragraph, entity:paragraph:evenement_programmations, entity:paragraph:itineraire_poi, entity:paragraph:recette_ingredients, entity:paragraph:recette_instructions, entity:paragraphs_type, entity:entity_form_display, entity:entity_view_display, entity:entity_form_mode, entity:entity_view_mode, entity:date_format, entity:base_field_override, entity_reference, field_item:address, field_item:address_zone, field_item:address_country, field_item:comment, field_item:commerce_remote_id, field_item:commerce_plugin_item:commerce_condition, field_item:commerce_plugin_item:commerce_promotion_offer, field_item:commerce_plugin_item:commerce_subscription_type, field_item:commerce_plugin_item:commerce_prorater, field_item:commerce_plugin_item:commerce_shipping_method, field_item:commerce_adjustment, field_item:commerce_price, field_item:commerce_billing_period, field_item:commerce_scheduled_change, field_item:commerce_shipment_item, field_item:datetime, field_item:daterange, field_item:duration, field_item:entity_reference_revisions, field_item:file, field_item:file_uri, field_item:geolocation, field_item:image, field_item:link, field_item:metatag, field_item:office_hours, field_item:list_float, field_item:list_string, field_item:list_integer, field_item:path, field_item:physical_measurement, field_item:physical_dimensions, field_item:redirect_source, field_item:state, field_item:telephone, field_item:text_with_summary, field_item:text_long, field_item:text, field_item:viewsreference, field_item:webform, field_item:yoast_seo, field_item:email, field_item:integer, field_item:float, field_item:uri, field_item:string_long, field_item:decimal, field_item:map, field_item:created, field_item:password, field_item:timestamp, field_item:entity_reference, field_item:boolean, field_item:string, field_item:uuid, field_item:language, field_item:changed, timestamp, language, boolean, timespan, any, language_reference, integer, duration_iso8601, map, email, string, datetime_iso8601, list, float, uri, binary dans Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (ligne 53 de /var/www/www-example-com/web/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php).

tommiecrawford’s picture

The new node is not added as a related entity in groups with the chosen group(select widget) with patch #124. Anyone else also got this issue?

I followed these steps:

1. Go to "Manage Fields" for the content type do you want to add in groups.
2. Add a new field of type Reference > Other.
3. For the option "Type of item to reference" select Content > Group. (Not group content).
4. The option "Allowed number of values" depends on your expected behaviour.
On the next screen select all the group content bundles needed in "REFERENCE TYPE", I'm planning to do an improvement to set them as default value.
5. Go to "Manage Form Display" and select the widget "Group Selector" for the field you just created.

I can see the groups but when i save the node nothing happens in groups.

michfuer’s picture

Status: Reviewed & tested by the community » Needs work
Related issues: +#3054622: Config export for group content names with hash not machine name

Can confirm #136. If you try to create a node with a group config constructed ID that's greater than 32 chars, the error is triggered.

It appears the group module hashes the config ID when it's over the limit

  # web/modules/contrib/group/src/Plugin/GroupContentEnablerBase.php
  public function getContentTypeConfigId() {
    $preferred_id = $this->getGroupTypeId() . '-' . str_replace(':', '-', $this->getPluginId());

    // Return a hashed ID if the readable ID would exceed the maximum length.
    if (strlen($preferred_id) > EntityTypeInterface::BUNDLE_MAX_LENGTH) {
      $hashed_id = 'group_content_type_' . md5($preferred_id);
      $preferred_id = substr($hashed_id, 0, EntityTypeInterface::BUNDLE_MAX_LENGTH);
    }

    return $preferred_id;
  }

The only related line I see in the stack trace is
Drupal\gcontent_field\Plugin\Field\FieldWidget\GroupSelectorWidget->elementValidate(Array, Object, Array)

Should this patch be correcting the plugin ID before passing to Drupal core?

zenimagine’s picture

There is another problem with the group field, it can not be used with a relation from a node. This poses problems with views, messages, and tokens. It's not really a field.

Can not go back to the parent group of a node.

esolitos’s picture

@zenimagine I usually create views if GroupContent instead of Content, because it decreases the amount of JOINS.

But, a part from that, it's definitely possible to go down this path: Node -> GroupContent -> Group -> GroupContent -> Node, and you can access all the fields of each of those entities.

The naming of the relationships is not the best, something like "Content from group content" to access the Node when you have a GroupContent.

BTW: I'm not sure also that your report is related to the current issue.

zenimagine’s picture

jidrone’s picture

Status: Needs work » Needs review
StatusFileSize
new66.49 KB
new2.99 KB

Hi Everyone,

Here is a new patch with the following:

  • Fixed issue reported in #136
  • Some code standard improvements.
  • Some unused variables removed.
michfuer’s picture

I reviewed the test failures for the patch in #142, and they're all

Error: Call to a member function getBaseFieldDefinitions() on null

And appear to be coming from this core update
https://www.drupal.org/project/drupal/issues/3035953

specifically

@@ -266,7 +284,7 @@ public function getViewsData() {

     // Load all typed data definitions of all fields. This should cover each of
     // the entity base, revision, data tables.
-    $field_definitions = $this->entityManager->getBaseFieldDefinitions($this->entityType->id());
+    $field_definitions = $this->entityFieldManager->getBaseFieldDefinitions($this->entityType->id());

which is called in

// GroupContentViewsData.php
$data = parent::getViewsData();

Not sure if the failures should be a blocker for approving this patch since I'd expect other patches to fail similarly. Maybe we need a separate issue to track?

dan_metille’s picture

I'm having an issue, when editing/creating group content via an Entity Reference field and the Inline Entity Form: the group selector is visible, but group is not saved. For that I have to edit that created referenced node separately and then only I'm able to attribute a group to that node.

I'm using that approach because I'm writing blog post, with some part of them is only visible to group members (the referenced entity). It would be great if I could attribute a group to the referenced entity while editing the 'parent' node and the Inline Entity Form.

Is it possible to fix this?

jidrone’s picture

I addressed the error on tests mentioned in #143 by creating this new issue #3061353: Replace deprecated EntityManager and add EntityFieldManager in GroupContentViewsData because they are not related to this patch.

michfuer’s picture

I updated the patch to account for nested Add to Group forms. I tested it with a media entity reference field using the 'Inline entity form - Complex' widget, and was able to successfully add the parent node to a group as well as a new inline media entity.

dww’s picture

Finally had a chance to review and test this again. Excited this is getting close!

Our sandbox has fallen behind patch #142, so I'm testing that directly.

NW for:
#90.4a
#90.8
screenshot of comment 90.8 error for users without group perms

I still find #90.9 clumsy and limited. If we're going to have all the different formatter options, can we have a more powerful/flexible choice for parent group that provides:

...the options for label-only (with and without a link to the group entity itself), id, or a full rendered entity

? Looks like @anruether agrees in #117. Does that need to be a follow-up feature request? @jidrone's answer in #91.9 doesn't really make sense to me:

The field on this patch is referencing the group content entity instead of group, it is especially useful for example in user membership, because it gives the possibility to configure the group roles.
Then you can set the formatter as referenced entity and show a summary of user membership.

But the gcontent_field module and everything it provides only injects itself as a field on content associated with groups (at least in my testing). For example, I don't see any mention of it at:
/admin/group/content/manage/private-group_membership/form-display
I'm confused how this computed field + widget on group content (e.g. events, private pages, etc) can be used to subscribe users to groups?
As it is in #142, the widget's behavior is wildly different depending on what widget you use (more than usual). ;) You get fundamentally different possible target entities, not just different ways to select from among the same set.

Behold:
Autocomplete
Checkboxes
Select

If I try to even use IEF and then visit a private_page entity form, I get WSOD with:

The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to Drupal\group\Plugin\GroupContentEnabler\GroupMembership::createAccess() must implement interface Drupal\group\Entity\GroupInterface, null given, called in /Applications/MAMP-common/htdocs/breema-d8/web/modules/contrib/group/src/Entity/Access/GroupContentAccessControlHandler.php on line 30 in Drupal\group\Plugin\GroupContentEnabler\GroupMembership->createAccess() (line 116 of modules/contrib/group/src/Plugin/GroupContentEnabler/GroupMembership.php).

The only one that works at all is Group Selector where the available choices make sense (in both select and autocomplete variants).
(Side nit #147.2: the convention in core / contrib is that this should be 'Group selector' (no 'S', only 's')).

I honestly think this field would be safer if we forced the group selector widget. Everything else (as a form display widget choice for this magic field) seems to not give anyone what they want. How can any of those screenshots possibly be the right UI for a content editor creating private content to add to a group?

Also unaddressed:
#113
#127 and #128

Meanwhile, #146 includes syntax errors, so we can't really review/test it. But if that's a bug, it's unaddressed, too.

Thanks!
-Derek

p.s. Updating the summary for remaining tasks. Let's cross off stuff if we have working patches that address any of it. Thanks! Also hiding a bunch of old files.

dww’s picture

Issue summary: View changes

Fixing minor formatting bug in the summary, adding link to 147.

dww’s picture

Issue summary: View changes
StatusFileSize
new39.08 KB

Some additional NW items:

  1. +++ b/modules/gcontent_field/gcontent_field.info.yml
    @@ -0,0 +1,7 @@
    +name: 'Group Content Field'
    +description: 'Defines a group content field type.'
    

    These could use some help. Something explaining a bit more about what this magic computed field provides, at least for the description. Something like:

    description: Defines a field to view and edit the groups that content belong to.

    (or something -- better alternatives welcome).

  2. +++ b/modules/gcontent_field/gcontent_field.tokens.inc
    @@ -0,0 +1,62 @@
    +          'ty pe' => $field_token_name,
    

    Looks like a typo 'ty pe'.

  3. +++ b/modules/gcontent_field/src/Plugin/Field/FieldWidget/GroupSelectorWidget.php
    @@ -0,0 +1,1184 @@
    +    $add_more_elements['add_relation'] = [
    +      '#title' => $this->t('Group'),
    +      '#type' => 'select',
    +      '#description' => $this->t('Select a group'),
    +      '#options' => $allowed_groups,
    +    ];
    

    If $allowed_groups is empty, this gives you an empty select dropdown form element. For example, if a piece of content already belongs to all the possible groups. The form element should disappear once all the groups are gone or none are available.
    Screenshot of an empty select once all groups are added.

  4. Same story for autocomplete. Once all the groups are assigned, the autocomplete form element should disappear.

Thanks!
-Derek

zenimagine’s picture

Hi, I applied the last patch to the module. How to display the parent group of a node in the Message module with Token?

I tested the token below and it does not work :

[message:field_node_reference:entity:group_content:entity:group:title]

[message:field_node_reference:entity:group_content:entity:group:title]
[message:field_node_reference:entity:group_content:group:title]
[message:field_node_reference:group_content:entity:group:title]
[message:field_node_reference:group_content:group:title]
[message:field_node_reference:entity:group:entity:group:title]
[message:field_node_reference:entity:group:group:title]
[message:field_node_reference:group:entity:group:title]
[message:field_node_reference:group:group:title]

dww’s picture

Issue summary: View changes
StatusFileSize
new67.07 KB
new2.41 KB

This fixes everything from #149.
Pushed to the sandbox as commit a20f1ec
Still NW (see summary and #147)

dww’s picture

Issue summary: View changes
StatusFileSize
new67.03 KB
new427 bytes

I was in a hurry when I uploaded #151. Left stray garbage in the .info file while fixing #149.1. This patch actually works. ;) Still needs help for all the open points.

zenimagine’s picture

@dww Hi, thanks for the patch, can you integrate the token ? Because currently there is no dean to link the content to the group with the token.

Can not find token of the parent group of a node.

dww’s picture

Issue summary: View changes

@zenimagine: I don't currently need or care about the tokens, so that hasn't been what I've been testing and fixing. It's possible I fixed it "on accident" by correcting the typo I saw in #149.2 since that was in gcontent_field_token_info().

I just added #150 to the summary for remaining tasks. Please test patch #152. If it's now working, please cross off #150 from the summary as complete (wrapping in <del> tags like the others). Otherwise, someone who cares about the tokens will have to debug this and fix it (or document how it works if it's already working).

Thanks/sorry,
-Derek

p.s. Note to committers: d.o's issue credit heuristics think I should be the author of this patch. Definitely not. ;) Please use @jidrone as the author. Thanks!

dww’s picture

Issue summary: View changes
StatusFileSize
new67.19 KB
new3.14 KB
new5.2 KB

Fixed #127 and #128, pushed to the sandbox as commit 6cf1bfb34ed. I think this should pass on the default PHP 5 now...

Interdiffs against #152 (to see the 3 fixes from @catch) and against #142 (to see everything "I" fixed since @jidrone's last patch).

dww’s picture

Issue summary: View changes

Whoops, I missed the point in #117 that #85 / #109 is still broken. Added those to the summary's remaining tasks. (Another feature / aspect I don't care about, so hopefully someone with multiple group types can take a look). ;)

Cheers,
-Derek

geek-merlin’s picture

As of #146, while that patch might have been messed up, the interdiff seems to make sense. It drops the assumption that we're at the form root, else no changes. So someone(tm) might want to integrate that interdiff. Cool to see the ball rolling, kudos derek and everyone!

dww’s picture

Issue summary: View changes
Issue tags: +Needs tests
StatusFileSize
new67.22 KB
new1.12 KB

@axel.rutz re: #157 -- oh yeah, good point. The syntax errors are just the PHP7 null coalesce operators (now fixed) so this should pass on both PHP5 and PHP7. Integrated patch #146, fixed a very minor code style bug in it, pushed to the sandbox, crossed off from the summary. I did *not* test the case mentioned of using IEF.

We almost certainly need tests for at least some of this functionality (see #90.10). Tagging and adding to the summary.

Cheers,
-Derek

zenimagine’s picture

I tested the following Token with patch #158 :

[message:field_node_reference:entity:group_content:group:title]

[message:field_node_reference:entity:group_content:entity:group:entity:title]
[message:field_node_reference:entity:group_content:entity:group:title]

None work. In the first patch, tokens worked.

dww’s picture

Issue summary: View changes
StatusFileSize
new69.89 KB
new6.4 KB

This fixes #90.9 (see also #117 and #147).

I started down the road of making the single ParentGroupFormatter class support more settings to determine what kind of formatter you want. Then I realized the whole thing was extending the EntityReferenceEntityFormatter and saw how much code I'd have to duplicate from the other EntityReference*Formatter classes to support the other display types (label + ID).

So, then I split ParentGroupFormatter into 3 formatter classes, ParentGroup(Entity|Id|Label)Formatter, each extending from the corresponding EntityReference*Formatter. I put the magic from getEntitiesToView() into a trait that's shared among all 3 (can't use a base class since each formatter needs to extend a different EntityReference*Formatter class).

Given the shared trait, the 3 formatter classes are now very simple. Only ParentGroupEntityFormatter needs to override any parent methods (to get the right view_mode options for groups). The other two are exactly the parent formatter classes, with the overridden getEntitiesToView() from the trait.

The trait itself might want a rename (currently "ParentGroupFormatterGetEntitiesTrait").

Otherwise, we now have all the display flexibility we might want for this (especially ParentGroupLabelFormatter with an option to link to the group or not).

Cheers,
-Derek

dww’s picture

StatusFileSize
new69.89 KB
new553 bytes

This fixes #147.2 (s/Group Selector/Group selector/).

Note: the fails on #158 for 8.8.x core are due to #3061353: Replace deprecated EntityManager and add EntityFieldManager in GroupContentViewsData not this patch. We shouldn't test against 8.8.x until #3061353 is fixed.

dww’s picture

Issue summary: View changes
StatusFileSize
new69.9 KB
new2.53 KB

Fixes code style bugs being warned about in https://www.drupal.org/pift-ci-job/1338423

However, I really don't like that modules/gcontent_field/css/gcontent-field.admin.css targets everything first via a .js selector. I think we should remove that, although I haven't actually tried it, yet. Maybe @jidrone can comment on why the patch defines those styles in that way. Adding this to the summary as a @todo.

dww’s picture

StatusFileSize
new69.91 KB
new996 bytes

Bah, missed a few more code style problems I had introduced in #160.

anruether’s picture

Thanks for your work, Derek!

I tested #163 and saw this if you add a regular group reference field after enabling gcontent_field:

Widget and Formatter of regular group reference fields are identical to those of the new field. This leads to WSOD when for the reference field...
- in the widget, you select Group Selector
- in the formatter, you select Parent Group ... (for a group reference field this option doesn't make any sense anyways)

I guess those settings shouldn't be there in the first place ?! Let me know if you need the full backtrace:

Error: Call to undefined method Drupal\group\Entity\Group::getGroup() in Drupal\gcontent_field\Plugin\Field\FieldFormatter\ParentGroupLabelFormatter->getEntitiesToView() (line 23 of /var/www/html/web/modules/contrib/group/modules/gcontent_field/src/Plugin/Field/FieldFormatter/ParentGroupFormatterGetEntitiesTrait.php)

dww’s picture

Issue summary: View changes

@anruether re: #164: Ugh, yeah. I see exactly what you mean. This is a Big Problem(tm) with the approach in this patch. The custom computed field here is "just" an entity_reference field type. So, the formatters and widget are configured to apply to that field type, and therefore they show up *everywhere* in the field_ui when you're touching any kind of entity_reference field. :(

I think the Right Way(tm) to deal with this is that instead of just defining our own custom GcontentFieldItemList class and configuring this magic entity_reference field to use it, we should really define a new, custom field *type* for all this. It should simply extend entity_reference, but have a different field type ID. Then, the custom formatters and widget will target the custom field type. That way, these magic formatters and widget won't "leak" out into other entity reference types.

That's +1000 from me, but I fear @jidrone won't like it, since it'd mean we'd completely resolve #90.9 in my favor: namely, that the "other" ways to format these group_content entities wouldn't keep "working" (if you call the screenshots in #147 "working"). ;)

Short of that, I don't know of any way to hide the formatter(s) and widget(s) from the "wrong" kinds of entity_reference fields. We only get a plugin annotation, and at that level, all we have to work with is a specific field type. We don't get to test properties of the entity the field is attached to, etc. Maybe someone else knows a way around this.

@joachim re: #113:

+ if ($entity_types = gcontent_field_get_entity_types()) {
Isn't this going to be circular?

I don't see how. There's no call to gcontent_field_get_entity_types() inside gcontent_field_get_entity_types(). The code you quoted is inside gcontent_field_entity_base_field_info(), which calls gcontent_field_get_entity_types() which does a bunch of stuff but I don't see how anything in there would trigger another call to gcontent_field_entity_base_field_info().

Crossing #113 off the list of remaining tasks. @joachim please clarify if I'm misunderstanding your concern.

@zenimagine re #165 - nope, I didn't change the field name. But I *did* change the IDs for the field formatter, so existing sites running the patch will have to re-save their 'Manage display' world on any group-enabled content types to get the formatters working again.

zenimagine’s picture

@dww Yes, thank you indeed, you have to save the display again. I was too fast in my comment.
But concerning Tokens, the last patch does not correct. With the Message module, I created a message template for the new nodes and I was unable to trace the name of the parent group.

dww’s picture

Issue summary: View changes

@zenimagine re: #167: Yup. The brokenness of tokens is: a) already in the summary of remaining tasks, b) something I already said I don't care about (or more accurately, the project I'm currently working on that needs this functionality doesn't care about) and therefore it's not something I'm going to be able to fix for you. Sorry.

Meanwhile, cleaning up some other aspects of the summary that either had typos/grammar bugs, or were out-of-date based on recent changes.

geek-merlin’s picture

@dww #166;
> The custom computed field here is "just" an entity_reference field type. So, the formatters and widget are configured to apply to that field type, and therefore they show up *everywhere* in the field_ui when you're touching any kind of entity_reference field. :(

I did not fully grok the problem, but i guess a solution without making up a new field type ID might (or might not) come from \Drupal\Core\Field\WidgetBase::isApplicable / \Drupal\Core\Field\FormatterBase::isApplicable ;-)

dww’s picture

Re: #169: Cool, that sorta helps. ;) This takes advantage of that method to hide the custom formatters and widget unless the field is our custom computed field.

However, I still think our own (unique) field type would be better, since:

a) This patch is a hack, hard-coding the field name to 'group_content' and type (entity_reference). I don't think there's a safe way to really know that's what our computed field is called, and hard-coding the field name like this seems like a major hack. However, I don't know how else to identify our field since it's re-using 'entity_reference' type.

b) While this hides the custom formatters and widget from other entity_reference fields (yay -- solves #164), all the (IMHO totally bogus -- see #147) alternate widgets and formatters for entity_reference fields still appear when configuring the group_content computed field. @jidrone probably thinks that's a feature. I consider it a bug. ;)

Anyway, it's here for consideration. I'm not sold this is the right solution, but it's better than nothing.

jonathanshaw’s picture

Maybe there's a compromise on #90.9:
go for a custom field type, but then opt in to the formatters / widgets that could be useful to someone with the right settings and config, but not to those that cannot be made useful without custom development work no matter how you configure them.

jidrone’s picture

Hi everyone,
Yes, I think we can go for a custom field type, I'm going to explain better why a Rendered entity formatter makes sense:
Any content entity type can be added as Group Content is the needed plugin is provided, out of the box the group module has support for Users and Nodes.
The field provided by this module detects all entity types with support for groups and adds the field to them.
Here is where the formatter can be useful:

  • You can add users to groups (Group memberships) by using this field.
  • Create a view mode for the group content(Group membership).
  • In user manage display select the Rendered entity formatter for the group_content field.
  • Set the view mode previously created.
  • Now when you see the user account you can see a list of their memberships.
dww’s picture

@jidrone re: #172: Thanks for the reply. Indeed, I recently discovered that the field shows up directly on user entities, letting you manage group memberships while editing a user. At #147 I foolishly thought it would be on the group content relationship entities (which didn't make sense):

For example, I don't see any mention of it at:
/admin/group/content/manage/private-group_membership/form-display
I'm confused how this computed field + widget on group content (e.g. events, private pages, etc) can be used to subscribe users to groups?

...but I hadn't noticed the field on users (yet). Given that, yes, I see there could be reasons to show the relationship entities (the membership itself, including the group roles, etc) not just the parent group. I've been looking at this issue entirely from the content side, not users.

So yeah, we probably need to retain the "raw" entity reference formatters for the new field type, although arguably we can get rid of the other widgets since I don't see how the other widgets help, even for the user case.

If we go with a new custom field type, probably the cleanest way to propagate the other entity reference formatters to them is to have trivial classes that extend the core formatter classes, but use different plugin IDs and target our custom field type. More or less like the new formatters I added in #160, only without needing to use the trait to override getEntitiesToView().

Anyway, I hope you get a chance to work on some of the remaining items, since I'm basically out of time for right now, and will be busy at least for the next 3+ weeks.

Thanks!
-Derek

geek-merlin’s picture

> If we go with a new custom field type, probably the cleanest way to propagate the other entity reference formatters to them is to have trivial classes that extend the core formatter classes, but use different plugin IDs and target our custom field type.

hook_field_widget_info_alter / hook_field_formatter_info_alter ?

jidrone’s picture

Hi everyone,
Latest commit to https://www.drupal.org/sandbox/dww/3045926, has the new field type approach for you to test, with the hook_field_formatter_info_alter.

dww’s picture

Issue summary: View changes
StatusFileSize
new70.95 KB
new5.57 KB

@jidrone re: #175: Thanks! Looks good. Here's the latest in patch form for anyone not using the sandbox (which is a good idea -- patching the latest group is better than relying on the sandbox, since I'm not keeping the sandbox sync'ed up with the rest of group (99% of what we're doing is in a whole new module)). Haven't had a chance to test yet, but the commit/interdiff looks right. ;)

One question is if the hook_field_formatter_info_alter() implementation should inject the group_content field type into the available field types for the entity_reference_entity_id and entity_reference_label formatters, too. IMHO, seems like it should.

Otherwise, I think we're done with the concerns in #164 (and #166) so I'm crossing those off the list in the summary.

Progress! :)

Cheers,
-Derek

anruether’s picture

regarding my comments in #109:
1. The Group selection on node/add forms needs the "Relationship: Add entity relation" permission, although the "Entity: Add content entities" permission should suffice"Entity: Add content entities" is enough with patch from #176
2. a) Node add form: If the user does have the permission to remove a relation, he/she cannot change the group after setting it once (before saving the node form). Seeing how 2b behaves this looks like a bug. I would even say, the user should be able to change the group as long as the node hasn't been created no matter if he has any permission to edit/remove the relation.

b) and c) are just for background info, no issue here:
b) (Node edit form: If the user does have the permission to remove a relation, he/she can remove the relation and add the node to a new group. This works as expected.)
c) (Node edit form: If the user does have a "Relationship: Edit .." permission, he/she can see an edit button. On clicking it a collapse button appears, after clicking that the edit button appears with the message "You have unsaved changes on this item.". On this roundtrip I cannot change the group setting, which is correctly indicated by the "You are not allowed to remove this item." however if there were any fields on the relation, those could be editable. So, I assume this works as expected as well.)
3. It only works with the default group type, not with any custom group type. There I'm getting a similar error as #77 cannot reproduce with patch from #176

Updating the summary accordingly.

anruether’s picture

Issue summary: View changes
jidrone’s picture

Issue summary: View changes

Fixed tokens and removed .js class from gcontent-field.admin.css because is not really needed for it to work.

Also updated summary.

jidrone’s picture

I forgot the patch.

jidrone’s picture

Regarding to #90.8 I think the problem was a wrong message.

After patch #91 the behavior is the following:

Member of groups without permissions (existing group relations)

Member of groups without permissions (new node)

Do you think we need to remove the field when adding a new node?

zenimagine’s picture

@jidrone Thanks, the tokens works

damienmckenna’s picture

I think it'd be also useful to add some documentation, even a simple README.txt file with a paragraph or two explaining the intended use scenario would be incredibly helpful.

damienmckenna’s picture

I tried out patch #180, set up the field on a content type that pointed to the "group" content entity, but get this AJAX error when I click the "Add to group" button:

ResponseText: Error: Call to undefined method Drupal\group\Entity\Group::getGroup() in Drupal\gcontent_field\Plugin\Field\FieldWidget\GroupSelectorWidget->formElement() (line 205 of modules/contrib/group/modules/gcontent_field/src/Plugin/Field/FieldWidget/GroupSelectorWidget.php).

damienmckenna’s picture

For what it's worth, I tried both field widgets (select, autocomplete) and they both gave the error from #184.

michelle’s picture

EDIT: Nevermind this. It must have been something in our custom code affecting it. The lead on the project was able to get it working on his branch.

I am not having any luck getting the patch in #180 to work. I added the new field to the basic page type and the went to the "all entities" tab on the group and tried to add an existing basic page. When I do that, I get a fatal error in this code:

  public function postSave($update) {
    if ($this->valueComputed) {
      $host_entity = $this->getEntity();
      $gcontent_ids = [];
      foreach ($this->getIterator() as $delta => $item) {
        $gcontent_entity = $item->entity;
        $gcontent_entity->entity_id = $host_entity->id();
        // Saving entities.
        if (isset($item->needs_save)) {
          $gcontent_entity->save();
        }
        $gcontent_ids[] = $gcontent_entity->id();
      }
      // Deleting entities.
      $group_contents = GroupContent::loadByEntity($host_entity);
      foreach ($group_contents as $gcontent_id => $gcontent_entity) {
        if (!in_array($gcontent_id, $gcontent_ids)) {
          $gcontent_entity->delete();
        }
      }
    }
    return parent::postSave($update);
  }

$gcontent_entity = $item->entity; doesn't work because $item->entity returns null. That gets a fatal error in $gcontent_entity->id(); when it's expecting it to be an object. I tried changing that to getEntity() instead but that gets the basic page node, which doesn't seem to be what is wanted there. I wasn't able to figure out where "entity" was supposed to be added so am having no luck getting past this.

meecect’s picture

Is it possible to configure this field as _not_ readonly? Like so:

->setReadOnly(FALSE)

in gcontent_field_entity_base_field_info?

There seems to still be some confusing discusison around what that property is to mean. I saw some talk of it here:

https://www.drupal.org/project/drupal/issues/2350429

The reason I would like it to not be readonly is that I am piggy-backing on top of this module to create a group content target plugin for the Feeds module. When the field is set to readonly, the Groups field does not show up as a target that can be configured in the Feed Target Mappings.

There is more discussion of that feeds target here:

https://www.drupal.org/project/group/issues/2991293

damienmckenna’s picture

Ok, upon further testing I've found that it does actually work.

However, I have other concerns:

  • As with other folks, this not being a real field (and I guess Group's architecture as a whole) means that referencing the Group entity becomes an awful lot harder and will require much more contributed code (if not just custom code) to make it usable with Views, tokens for Pathauto, etc, etc.
  • I'm not sure this would help with migrations?
  • If a group is selected on the field's selector, but the "add to group" button is not selected, the group selection is not saved.
joe huggans’s picture

Trying to test this new feature but encountering an error, a warning and several notices when creating a field. Steps to reproduce

- Clean D8 installation
- Install Group module
- Apply patch
- Create group type
- Add "Groups" field to group type referencing content of "basic page"

Error: Call to a member function uuid() on null in Drupal\Core\Field\EntityReferenceFieldItemList->defaultValuesFormSubmit() (line 126 of /var/www/html/session-group-ui/core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php) #0 /var/www/html/session-group-ui/core/modules/field_ui/src/Form/FieldConfigEditForm.php(197): Drupal\Core\Field\EntityReferenceFieldItemList->defaultValuesFormSubmit(Array, Array, Object(Drupal\Core\Form\FormState)) #1 [internal function]: Drupal\field_ui\Form\FieldConfigEditForm->submitForm(Array, Object(Drupal\Core\Form\FormState)) #2 /var/www/html/session-group-ui/core/lib/Drupal/Core/Form/FormSubmitter.php(111): call_user_func_array(Array, Array) #3 /var/www/html/session-group-ui/core/lib/Drupal/Core/Form/FormSubmitter.php(51): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState)) #4 /var/www/html/session-group-ui/core/lib/Drupal/Core/Form/FormBuilder.php(590): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState)) #5 /var/www/html/session-group-ui/core/lib/Drupal/Core/Form/FormBuilder.php(319): Drupal\Core\Form\FormBuilder->processForm('field_config_ed...', Array, Object(Drupal\Core\Form\FormState)) #6 /var/www/html/session-group-ui/core/lib/Drupal/Core/Controller/FormController.php(93): Drupal\Core\Form\FormBuilder->buildForm('field_config_ed...', Object(Drupal\Core\Form\FormState)) #7 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch)) #8 /var/www/html/session-group-ui/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array) #9 /var/www/html/session-group-ui/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #10 /var/www/html/session-group-ui/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #11 /var/www/html/session-group-ui/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) #12 /var/www/html/session-group-ui/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #13 /var/www/html/session-group-ui/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #14 /var/www/html/session-group-ui/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #15 /var/www/html/session-group-ui/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #16 /var/www/html/session-group-ui/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #17 /var/www/html/session-group-ui/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) #18 /var/www/html/session-group-ui/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #19 /var/www/html/session-group-ui/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #20 /var/www/html/session-group-ui/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #21 /var/www/html/session-group-ui/core/lib/Drupal/Core/DrupalKernel.php(693): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #22 /var/www/html/session-group-ui/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #23 {main}.

jazzfiction’s picture

1) Regarding #184, also I found that you can't create a field pointed to 'Group' content entity, but you must use the preexisting field found in Manage from display. I also got the same error. This confused me at first until I saw the preexisting field. I think if the user is suppose to use the preexisting field, then the 'Group' entity needs to be removed from the entity list so you can't create a custom field with it. Content Moderation's 'Moderation State' field is an example of this.

2) In testing patch from #180, I found that there is a permission issue. When a member of a group has been given permission to edit or add relations via permissions given by a role in the 'Advanced Outsider Permissions', a warning pops-up that states 'This entity (node: 88) cannot be referenced.' Only when I add the user to a group role with the same permissions does this warning go away.

The first screen shot is the permissions that I set for both outsider and group roles. The second screen shot shows the errors with just outsider permissions. The third is the same content item with the group role applied.

jazzfiction’s picture

When I uninstalled the module, when it removed the Group entity from the 'Manage Form Display' tab, it also disabled everything that wasn't default for a content type, and removed my field groups. I had to recreate my field groups, move everything back into place, and change back all of the field settings.

damienmckenna’s picture

FWIW because of the extra layer of abstraction required for Group, we've switched to using OG for this sort of functionality on new projects as it's a much simpler system, and this rudimentary requirement works as expected.

meecect’s picture

@DamienMcKenna, we did the same here.

psf_’s picture

If we are using field group and we have a group with the name "group_content" the field in the patch is not visible.

joshuami’s picture

@DamienMcKenna, can you say more about your use of OG for this purpose? I have been following OG development for D8 and the last release still does not have have a UI for managing roles and permissions within a group. Lack of roles and permission prevents us from using it, but I want to make sure I'm not missing something.

One thing I like about the approach is issue is taking is that you can display the form for the group content as part of adding the group. This means we could add fields for featuring content on a group for a period of time on the group content entity rather than on the content node itself. That flexibility is a nice feature.

I have the patch from #180 running successfully against Drupal 8.6.7 and Group 8.x-1.0-rc4. I can add content to multiple groups fairly easy, but there is a small gotcha in that the field allows you to override the cardinality in the content plugin settings. So you have the ability to say it should only have one group in your plugin config and allow it to have multiple in the field settings. The field settings override the group plugin settings on the node edit form only.

The need to click "add group" is going to be problematic for some use cases, but for migration I think we might be able to run two scripts, one to create the content and then a second to create the group content nodes adding the content to the group.

@kristiaanvandeneynde, what are the chances of this approach making it into the 1.0 release of Group?

dww’s picture

Issue summary: View changes
Issue tags: +needs documenting
Related issues: +#2350429: Clarify the meaning of read-only fields and properties

@jidrone re: #181:

Do you think we need to remove the field when adding a new node?

No, I think we should hide the parts of "the field" for users that don't have permission to use them. Re-quoting #90.8:

If the current user doesn't have permission to add content to a group, the widget should hide those aspects completely, and only show current group memberships in a read-only listing.

Users should only see the parts of the widget that they can use. E.g. anyone can see if a given node belongs to any of the groups they're members of, but only users with sufficient privs should see the stuff about adding a node to new groups, etc. If I'm not allowed to remove it, I don't need a huge yellow warning. I just need to see the group names without any operation buttons. Hope that clarifies the intention of #90.8

New UI ideas/points:

#196.1: The widget should really render as a "details" container ("fieldset" in D7 and before), e.g. like entity_browser does, since it's got a bunch of related form elements.

#196.2: Not clear why the widget is using tabledrag. What does the order of groups on a node edit form impact? Nothing, right? We don't save those as deltas with the computed field or anything, right?

@DamienMcKenna re: #183: Agreed, some docs would help. Tagging as such.

@meecect re: #187: Hrm, not sure. I don't yet fully grok the implications of readonly or not.

@jazzfiction re: #190.1: Yup, that answers #189.
re: #190.2 and #191: Added to summary as bugs to fix. Good finds.

@psf_ re: #194: Heh, yeah. Not exactly sure what to do about that. :/ Namespace collisions waiting to happen in all this. Added to summary.

@joshuami re: #195:
- Added cardinality bug to summary.
- re: 8.x-1.0: Sadly, given the long list of remaining tasks in the summary, I highly doubt this will make it into 8.x-1.0. However, since the vast bulk of this is an entirely separate sub module that sites have to opt-in to, I think it'd be a strong candidate for 8.x-1.1 if I understand @kristiaanvandeneynde right about release management and BC concerns from some other issues (sorry, don't have the links).

@all re: OG vs. group -- can we have that discussion elsewhere? It's off topic. Neither project page mentions the other, I don't know of any good comparisons, etc. Seems the community needs to write it/them. Can we do that elsewhere, like at #1457506: Differences between OG and group module, text for project page.? This issue is already huge, in danger of becoming totally un-readable. Please only post here if you're fixing the existing remaining tasks or have to add more to the list (in which case, please update the summary as you do).

Thanks!
-Derek

jonathanshaw’s picture

Isn't #190.1 (which explains #189) also a to-do?

dww’s picture

@jonathanshaw re: #197: Oh, whoops, I missed that there was a proposal at the end of #190.1:

I think if the user is supposeg to use the preexisting field, then the 'Group' entity needs to be removed from the entity list so you can't create a custom field with it. Content Moderation's 'Moderation State' field is an example of this.

However, I don't want to add that to the summary (yet), since I don't really understand the proposal. What does "the 'Group' entity needs to be removed from the entity list" mean? What list of entities? You mean entities available for use via an entity_reference field? No way, we can't remove that. Folks might want to use an entity_reference field pointing to group entities (or even group_content entities) for all sorts of other things. This issue is not a complete replacement for all possible fields that touch group-esque things. If a site builder actually tries to use a regular entity_reference field for this functionality instead of the field provided by the gcontent_field module, I'm not sure there's much this patch can do about it to help them (other than provide good docs, as already tagged/listed in the summary).

#190.1, as written, isn't actionable for the summary, so I'm leaving it off. If someone can clarify a legitimate (specific) change we should make to improve the UX/DX of this whole mess, let's hear it.

Thanks!
-Derek

joshuami’s picture

Regarding 196.2 (tabledrag), it doesn't seem to save the order on node save. I could see the value of ordering the group relations. We plan to use this on news that can be posted on behalf of multiple offices within a government organization. There are often times when the "primary" group would be listed first in a list of groups that were all associated to the news.

It would be nice if the first group in that order was associated with the group tokens for that content. It would make path aliasing and breadcrumbing the content a bit more consistent.

dww’s picture

Re: #199: I have no idea where/how you'd store those deltas. This isn't a real entity reference field. It's computed based on the existence of other (group_content) entities. Those entities don't have any notion of weight/delta/etc, so we'd have to add them. #NeedsFollowup. ;) Or, we need to actually make this a real field. But I don't see any way to have weights/deltas matter given any of the current architecture, and it seems way out of scope to try to add all that to this already huge effort. I vote we remove tabledrag (since the weights are currently meaningless) and convert it back to tabledrag if/when there's somewhere to persistently store these weights.

michelle’s picture

Is there a reason it isn't a real field? It seems like that would make a lot of things easier. Perhaps just put the field machine name in config somewhere so it knows what field it needs to use for the syncing. Then you'd have all the benefits that go along with real fields like being able to use Views.

joshuami’s picture

@Michelle, the biggest reason for using a computed field is the architectural model of Group. Group stores the relationship between an entity and its group in a group content entity. That means the relationship isn't stored in the content entity itself.

If we added all of this functionality into an actual field, then we would have to synchronize any changes between the field and the group content entities. That is a lot of overhead. We did this on a project and were not very happy with the result. It required a lot of custom code to update both the content entity and the group content entity on any change from either direction.

By using a computed field, we are changing the group content entities themselves from within the content entity form.

@dww, I hear you about the deltas for group content entities. I agree it makes the scope a little more ungainly, but without some sense of order for the group content entities against the content entity, there is no meaning to the [node:groups] tokens. In those tokens, added by this patch, there is the notion of first and last in the list, but neither can really be used because first and last changes with every new group content entity created from this field.

I'm going to add a note to https://www.drupal.org/project/group/issues/2774827 to see if the work to add group tokens could consider the issue of multiple group content entities and their relative order. It might be something like adding a weight field to the group content entity so that if a content entity is related to multiple group content entities it can sort them.

artatac’s picture

Group_notify also shows the groups a node is associated with in the edit screen see
https://www.drupal.org/project/group_notify/issues/3076248#comment-13234219

tim.clifford’s picture

Hi all, great work so far on this submodule.

I've added the new 'Groups' field to an article content type and installed that as a group node (group_node-article) within a group.

However, when attempting to save this (with plugin group_node:article) with the new 'Add to Group' widget, an exception is thrown as the GroupContent entity doesn't exist yet.

The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">Drupal\Core\Entity\EntityStorageException</em>: Cannot load GroupContent entities for an unsaved entity. in <em class="placeholder">Drupal\group\Entity\Storage\GroupContentStorage-&gt;loadByEntity()</em> (line <em class="placeholder">84</em> of <em class="placeholder">modules/contrib/group/src/Entity/Storage/GroupContentStorage.php</em>). <pre class="backtrace">Drupal\group\Entity\GroupContent::loadByEntity(Object) (Line: 72)

So, I commented out this bit so the form would load.

    // No value will exist if the entity has not been created so exit early.
    // if ($this->getEntity()->isNew()) {
    //  return NULL;
    // }

    // $group_contents = GroupContent::loadByEntity($this->getEntity());
    if (empty($group_contents)) {
      return NULL;
    }

The problem of course now is that the 'target_id' is missing on save for the new Group Content Entity which would have been added by this:

$this->list[] = $this->createItem($delta, [
    'target_id' => $group_content->id(),
]);

Does anyone else see this issue? Is there a way to temporarily store an id which would then later be updated when saving the fields for the Group Content entity (i.e. the relationship part)?

kevin w’s picture

How to set the default value dynamically?

Thank you for the great patch! We have a requirement to set the default group dynamically inside a entity browser form widget. When I tried to set the widget state values selected_group and selected_bundle in the form_alter hook and call $form_state->setRebuild(), the widget doesn't get rebuilt with the new default group. Is it possible to set the widget state before GroupSelectorWidget::formMultipleElements() is invoked without changing code in GroupSelectorWidget? Thanks!

dianacastillo’s picture

didnt work at first but then i reinstalled the group module and repatched and seems to work now

michelle’s picture

@dianacastillo It's been a while since I looked at this but I believe you aren't actually supposed to add the field normally. That tripped me up as well. It's not a real field but rather some sort of fake pseudo-field that gets automatically added? Someone can probably explain that better than I can but I wanted to give you a quick answer to at least point you in the direction of the problem. :)

dianacastillo’s picture

@michelle you are right it gets automatically added but you have to go to the manage form display of the content type and make it enabled to see it in the form

michelle’s picture

@dianacastillo : Ah, sorry, I misunderstood what you did. Glad you got it working.

Side note, I wish d.o noted when a comment is edited. This exchange looks confusing because comment #206 was completely different when I responded to it. LOL

kristiaanvandeneynde’s picture

I'm a bit (actually, very) swamped right now, but I'd like to see this UX improvement go in.

Here's the minimum it would require:

  • An extension to GroupQueryAccessHandler so that we can filter on a list of groups you are allowed to add the entity to.
  • An entity reference field that allows you to select one or more Groups to add the entity to. This should be a form alter to the entity types' forms we want to see "quick assignment" enabled on. This ER field should fire its query with the right operation so that GroupQueryAccessHandler will trigger correctly.
  • Every content plugin needs to opt in or out to this "quick assignment", because if the GroupContent entities has mandatory fields, they could be bypassed through quick assignment, which is bad.
  • If multiple content plugins allow you to add e.g. nodes to a group, then for each plugin we need to show the quick assignment ER. Something like: Add to group as Group node, Add to group as Favorite, etc. Otherwise we can't know what plugin to use.
  • Some extra hardening so that you can only remove items from groups you are allowed to remove them from. Perhaps a table below the ER field that shows the assignments and has checkboxes in front of the lines you can remove with disabled checkboxes of the ones you can't remove? But then you need to build the table with a View query first so you don't expose groups that should be hidden. Then run a 2nd query to see which ones the user can remove items from.
  • TESTS

The goal is to not introduce extra storage (fields), but rather use the existing data architecture, query access handlers, etc. The only thing that needs to happen is a form alter, a submit handler and an extra boolean on content plugins to enable/disable this behavior.

I will be on Slack for the next few weeks, so ping me (kristaanvde) there if you want to work on this and need input. I'll try to get back to you in a timely fashion. I'm usually online between 10AM and 5PM CET.

kristiaanvandeneynde’s picture

If it makes your life easier, we could start with an assignment-only patch (i.e.: add to group only) and work our way through removing entities from groups on their edit forms in a follow-up.

dalra’s picture

dalra’s picture

Some extra hardening so that you can only remove items from groups you are allowed to remove them from.

The same needs to be done for adding content to groups.
#2771065: Group Node: Only authors should be able to create Gnodes for their nodes and #9.

dianacastillo’s picture

has anyone yet figured out a way to let a user only add groups he is a member of? I see that if he is not a member he gets the message "you cannot remove this item" because I did not give them permissions to "edit others content"

is there any way to make the select only show groups the person who is adding belongs to ?

arnaud-brugnon’s picture

Please, dont use private method.

With #179, it works for me expect that i cannot change my group list (because getAllowedGroups is private).

I replace all private method with protected method (so much better to override)

arnaud-brugnon’s picture

arnaud-brugnon’s picture

Sorry, wrong patch extension (stupid laptop)

moshe weitzman’s picture

The goal is to not introduce extra storage (fields), but rather use the existing data architecture, query access handlers, etc. The only thing that needs to happen is a form alter, a submit handler and an extra boolean on content plugins to enable/disable this behavior.

The part that I'm looking forward is actually the computed field part so that search_api integrates without any custom code (for example). Should we spin off a new issue for that? Or maybe thats simply not desired?

moshe weitzman’s picture

Or maybe the computed field work should resume at #2718195: Add a computed field for entity's group(s)?

avpaderno’s picture

Issue tags: -needs documenting +Needs documentation
geek-merlin’s picture

@moshe: ~100 comments ago we consolidated the 3 issues into this one (to rule them all), using a computed field approach.

zenimagine’s picture

#217 works well for me

quentin massez’s picture

Hello,

Thanks for the work !
I used the patch in #217, it also worked for me on my already installed sites.
But when I tried to install a new local site, I had a problem on a custom entity type defined by another module.
"The entity type doesn't exist".
Here is the new patch to avoid this issue on installation.

avpaderno’s picture

Status: Needs work » Needs review
plousia’s picture

Neither #217 nor #223 are working for me. The site is on 8.8.1 and I'm logged in as the root user. I've tried different Group permissions, but still no dice. I add a Groups field to the content type and set it to reference Groups. I can see the group names in the autocomplete and select them, but when I choose one and click "add to group" it continues saying "Not yet added to groups." When I save the node and re-edit, the field is empty.

I am using Workflow module (contrib, not core) and the "save" action is being provided by Workflow (different form submit buttons to save the node in different workflow states). That doesn't explain why it doesn't seem to register the group add on the node edit form, though. Am I missing something?

EDIT: I did get this working, though can't remember what the issue was.

roam2345’s picture

  • Setup two groups.
  • Added group field to a content type
  • Adding a new piece of content to one/multipal groups I get this stack trace.
  • Seems add one group at a time
Warning: Creating default object from empty value in Drupal\gcontent_field\Field\GcontentFieldItemList->postSave() (line 91 of /mnt/www/html/llsorgd8dev2/docroot/modules/contrib/group/modules/gcontent_field/src/Field/GcontentFieldItemList.php)
#0 /mnt/www/html/llsorgd8dev2/docroot/core/includes/bootstrap.inc(600): _drupal_error_handler_real(2, 'Creating defaul...', '/mnt/www/html/l...', 91, Array)
#1 /mnt/www/html/llsorgd8dev2/docroot/modules/contrib/group/modules/gcontent_field/src/Field/GcontentFieldItemList.php(91): _drupal_error_handler(2, 'Creating defaul...', '/mnt/www/html/l...', 91, Array)
#2 [internal function]: Drupal\gcontent_field\Field\GcontentFieldItemList->postSave(true)
#3 /mnt/www/html/llsorgd8dev2/docroot/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(881): call_user_func_array(Array, Array)
#4 /mnt/www/html/llsorgd8dev2/docroot/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(913): Drupal\Core\Entity\ContentEntityStorageBase->invokeFieldMethod('postSave', Object(Drupal\node\Entity\Node), true)
#5 /mnt/www/html/llsorgd8dev2/docroot/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(839): Drupal\Core\Entity\ContentEntityStorageBase->invokeFieldPostSave(Object(Drupal\node\Entity\Node), true)
#6 /mnt/www/html/llsorgd8dev2/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(535): Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('update', Object(Drupal\node\Entity\Node))
#7 /mnt/www/html/llsorgd8dev2/docroot/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(728): Drupal\Core\Entity\EntityStorageBase->doPostSave(Object(Drupal\node\Entity\Node), true)
#8 /mnt/www/html/llsorgd8dev2/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(460): Drupal\Core\Entity\ContentEntityStorageBase->doPostSave(Object(Drupal\node\Entity\Node), true)
#9 /mnt/www/html/llsorgd8dev2/docroot/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(837): Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\node\Entity\Node))
#10 /mnt/www/html/llsorgd8dev2/docroot/core/lib/Drupal/Core/Entity/EntityBase.php(395): Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object(Drupal\node\Entity\Node))
#11 /mnt/www/html/llsorgd8dev2/docroot/core/modules/node/src/NodeForm.php(294): Drupal\Core\Entity\EntityBase->save()
#12 [internal function]: Drupal\node\NodeForm->save(Array, Object(Drupal\Core\Form\FormState))
#13 /mnt/www/html/llsorgd8dev2/docroot/core/lib/Drupal/Core/Form/FormSubmitter.php(114): call_user_func_array(Array, Array)
#14 /mnt/www/html/llsorgd8dev2/docroot/core/lib/Drupal/Core/Form/FormSubmitter.php(52): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState))
#15 /mnt/www/html/llsorgd8dev2/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(591): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState))
#16 /mnt/www/html/llsorgd8dev2/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(320): Drupal\Core\Form\FormBuilder->processForm('node_event_edit...', Array, Object(Drupal\Core\Form\FormState))
#17 /mnt/www/html/llsorgd8dev2/docroot/core/lib/Drupal/Core/Controller/FormController.php(91): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\node\NodeForm), Object(Drupal\Core\Form\FormState))
the_glitch’s picture

Patch in comment #180 fails to apply
(group-field_to_view_and_edit_content_groups-2813405-179.patch)

cesardmoro’s picture

Patch #223 not working on latest dev module

$ git apply --verbose ./group/group-field_to_view_and_edit_content_groups-2813405-223.patch.txt

Skipped patch 'src/Form/GroupSettingsForm.php'.
Skipped patch 'src/Plugin/GroupContentEnablerManager.php'.
Skipped patch 'src/Plugin/GroupContentEnablerManagerInterface.php'.
Checking patch modules/gcontent_field/config/install/gcontent_field.settings.yml...
Checking patch modules/gcontent_field/css/gcontent-field.admin.css...
Checking patch modules/gcontent_field/gcontent_field.info.yml...
Checking patch modules/gcontent_field/gcontent_field.libraries.yml...
Checking patch modules/gcontent_field/gcontent_field.module...
Checking patch modules/gcontent_field/gcontent_field.tokens.inc...
Checking patch modules/gcontent_field/src/Element/GroupAutocomplete.php...
Checking patch modules/gcontent_field/src/Field/GcontentFieldItemList.php...
Checking patch modules/gcontent_field/src/Plugin/EntityReferenceSelection/GroupContentSelection.php...
Checking patch modules/gcontent_field/src/Plugin/Field/FieldFormatter/ParentGroupEntityFormatter.php...
Checking patch modules/gcontent_field/src/Plugin/Field/FieldFormatter/ParentGroupFormatterTrait.php...
Checking patch modules/gcontent_field/src/Plugin/Field/FieldFormatter/ParentGroupIdFormatter.php...
Checking patch modules/gcontent_field/src/Plugin/Field/FieldFormatter/ParentGroupLabelFormatter.php...
Checking patch modules/gcontent_field/src/Plugin/Field/FieldType/GroupContentItem.php...
Checking patch modules/gcontent_field/src/Plugin/Field/FieldWidget/GroupSelectorWidget.php...
Checking patch modules/gcontent_field/templates/gc-field-dropbutton-wrapper.html.twig...
Applied patch modules/gcontent_field/config/install/gcontent_field.settings.yml cleanly.
Applied patch modules/gcontent_field/css/gcontent-field.admin.css cleanly.
Applied patch modules/gcontent_field/gcontent_field.info.yml cleanly.
Applied patch modules/gcontent_field/gcontent_field.libraries.yml cleanly.
Applied patch modules/gcontent_field/gcontent_field.module cleanly.
Applied patch modules/gcontent_field/gcontent_field.tokens.inc cleanly.
Applied patch modules/gcontent_field/src/Element/GroupAutocomplete.php cleanly.
Applied patch modules/gcontent_field/src/Field/GcontentFieldItemList.php cleanly.
Applied patch modules/gcontent_field/src/Plugin/EntityReferenceSelection/GroupContentSelection.php cleanly.
Applied patch modules/gcontent_field/src/Plugin/Field/FieldFormatter/ParentGroupEntityFormatter.php cleanly.
Applied patch modules/gcontent_field/src/Plugin/Field/FieldFormatter/ParentGroupFormatterTrait.php cleanly.
Applied patch modules/gcontent_field/src/Plugin/Field/FieldFormatter/ParentGroupIdFormatter.php cleanly.
Applied patch modules/gcontent_field/src/Plugin/Field/FieldFormatter/ParentGroupLabelFormatter.php cleanly.
Applied patch modules/gcontent_field/src/Plugin/Field/FieldType/GroupContentItem.php cleanly.
Applied patch modules/gcontent_field/src/Plugin/Field/FieldWidget/GroupSelectorWidget.php cleanly.
Applied patch modules/gcontent_field/templates/gc-field-dropbutton-wrapper.html.twig cleanly.

dwkitchen’s picture

Status: Needs review » Reviewed & tested by the community

Was going to re-roll this patch but it is applying cleanly today.

Also, add it works adding the correct field to group content on Group 8.x-dev

jonathanshaw’s picture

Status: Reviewed & tested by the community » Needs work

I doubt this can be RTBC given #210?

dww’s picture

Indeed, NW for #210 plus the long list of remaining tasks in the issue summary.

However, I asked @kristiaanvandeneynde in Slack about this issue. In most cases, he's encouraging people to spin up standalone module projects for big features like this (see #2984315-56: Media enabler).

From our Slack exchange:

... huge patches should be avoided when possible
So if a huge patch can prove its worth in a separate module, go for it. It allows you to use more topical issues in its issue queue, clean up the module without 200-comment-long issues and then show it to me in a polished state

My opinion:

  • This issue is so big and unwieldy, it's hard to get anything done.
  • I think this would all move along faster and better if we move this into a separate contrib module.
  • We can then open smaller issues to track all the various remaining tasks and handle them more easily.
  • When the dust finally settles, we can ship an official 1.0.0 release that folks can use in production without applying patches and that whole mess.
  • If that stabilizes and proves its worth, we can consider merging it into Group core at a later date (or continue to let it live separately).

Open question: where should we move this?

  1. One option would be to use https://www.drupal.org/project/group_content_field for this. That's a pretty accurate name for what this feature does. That project had 1 commit 3 years ago, no further development, and no releases. I've pinged the maintainer to see if we can use that, clear out the code, and put this code in its place.
  2. Alternatively, we can claim and use something like "entity_group_field" (@kristiaanvandeneynde's naming suggestion), and start fresh.
  3. Or, we could re-use exactly "gcontent_field", but I think that's not a great name, and if we're going to migrate to a new project, we might as well start with a good name (although it makes life a bit harder for folks (like me) who are already using this patch in production).

Any strong opinions?
Anyone else want to be a co-maintainer from the start? @jidrone? ;) Others?

Thanks!
-Derek

jonathanshaw’s picture

+1, +1, and a hundred times +1.

Another advantage of 3 is that it makes migration of the field back into the module easy also. I'd make forwards comparability the main criterion for choosing a name.

esolitos’s picture

Any solution which reduces the amount patches we've applied it's definitely very welcome. :)

The only note is: I'm ok with any name, however if we move away from gcontent_field we should try as hard as possible to provide a upgrade path from the current name, because breaking sites it's not nice, and even less fun it's fixing them :D

dww’s picture

Re:

Another advantage of 3 is that it makes migration of the field back into the module easy also. I'd make forwards comparability the main criterion for choosing a name.

"gcontent_field" isn't any easier or harder to move back into Group core. The existing sub modules are "gnode" and "grolesync". There's no specific requirement on what the submodules are called, and even if there was, "gcontent_field" wouldn't necessarily be following it. ;) I don't see how "forwards comparability" favors any of the 3 choices. Ultimately, @kristiaanvandeneynde would have to weigh in on that, but I don't think it matters (beyond personal preference).

Re:

however if we move away from gcontent_field we should try as hard as possible to provide a upgrade path from the current name

Yeah, that's more of a concern. That's a fairly good reason to keep the current name. Also saves a few hours of work renaming everything in the code. ;) I'm leaning towards that, simply out of laziness. But this seems like our one and only chance to give this code a more proper name, so I wanted to get some input before unilaterally letting pragmatic laziness make the decision for me.

Thanks,
-Derek

kristiaanvandeneynde’s picture

If it helps: I'm trying to get rid of the gnode-like naming pattern. It's something I was forced to use for D7 because of hooks colliding all over the place (especially hook_group_permission vs hook_permission).

Try coming up with names that make sense, but avoid the pattern group_<ENTITY_TYPE_ID>, because those will keep causing issues until core finally gets rid of hooks altogether:

  • groupmedia rather than group_media
  • group_term rather than group_taxonomy
  • etc.

Otherwise you get confusion about group_node_access etc.: Is it hook_node_access() for Group or hook_access() for Group Node?

dww’s picture

@kristiaanvandeneynde: Yes, that is very helpful. It's a clear vote against #231.3, with other useful info and background. Thanks!

1. "group_content_field" should be totally fine, since "content" isn't an entity type (yet!). Maybe someone would do that in contrib/custom?

2. "entity_group_field" seems extremely safe from hook collision woes. But would it be weird to have a group core submodule that starts its namespace with "entity" not "group"?

3. "gcontent_field" is easy but you're trying to phase that out.

4. What about "group_entity_field"? Is that too generic? Misleading?

@kristiaanvandeneynde if you'd be willing to state a clear preference, it'd speed up this decision dramatically. ;)

Thanks!
-Derek

jonathanshaw’s picture

'group_contentfield' seems good to me.

maxilein’s picture

I like 'group_contentfield'.

jidrone’s picture

Hi everyone,

I initially named the module "gcontent_field" to be consistent with other submodules, but now that we are finding a new name I like group_content_field.

I want to be a co-maintainer and I'm organizing my time to be able to do so when we get an agreement with the name.

the_glitch’s picture

.

kristiaanvandeneynde’s picture

Ask yourself what the field does: It attaches to an entity and shows that entity's groups. So I'd say go with entitygroupfield or entity_group_field, although the latter is risky due to field hooks.

dww’s picture

Project: Group » Entity Group Field
Version: 8.x-1.x-dev » 1.0.x-dev
Component: Group (group) » Code
Category: Feature request » Plan
Issue summary: View changes
Issue tags: +Needs issue summary update, +Needs followup

Hello world:

https://www.drupal.org/project/entitygroupfield

@jidrone and I are co-maintainers for now.

I included the patches from #217 and #223 as separate commits to the sandbox, thanks for those!

Then I did the subtree split for only modules/gcontent_field, and pushed that to the new project's repo.

Immediate TODO:
- Needs the few changes outside the modules/gcontent_field directory to either move into here or become a patch against Group core if needed.
- Needs to be renamed to the new "entitygroupfield" namespace.
- Open follow-up for migration path for sites currently running gcontent_field via patch.

Next phase:
- Go through remaining tasks and #210 and split off child issues in the new queue, then update the summary to cross off that item with a [#x] link to the new issue.

Thanks, everyone!
-Derek

dww’s picture

Issue summary: View changes
Issue tags: -Needs tests, -Needs documentation

Opened a ton of child issues for everything else in the summary except #210.
Saving work in progress so I don't lose anything. ;)

dww’s picture

Issue summary: View changes
Status: Needs work » Fixed
Issue tags: -Needs issue summary update, -Needs followup

Opened child issues for everything else. Summary is now complete and accurate.

Entity Group Field needs a lot of help before we're going to cut any official releases, but to save us all from the pain of a #250 comment monster issue, I'm going to call this one fixed.

Please join me in the child issues if you want to see a 1.0.0 release. ;)

Thanks!
-Derek

plousia’s picture

Just want to say, thanks everyone for their hard work on this - this is such a great functionality and makes the module so much more useful. Three cheers!

Status: Fixed » Closed (fixed)

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