Gizra / og

https://www.drupal.org/project/og
92 stars 133 forks source link

Provide snippet to check the API on OG8 #62

Open amitaibu opened 9 years ago

amitaibu commented 9 years ago

@RoySegall

bdragon28 commented 9 years ago

Brandon here, watching issue.

RoySegall commented 9 years ago

I've downloaded devel, enabled devel and devel_kint. All the code is done in DevelEventSubscriber::onRequest.

Creating the fields:

    OG::CreateField(OG_GROUP_FIELD, 'node', 'group');
    // This one will break the site but create the field. Fix this one later.
    OG::CreateField(OG_AUDIENCE_FIELD, 'node', 'group_content');

Create a group and group content.

    // Setting up a group.
    $group = Node::Create([
      'type' => 'group',
      'title' => 'Group'
    ]);
    $group->set(OG_GROUP_FIELD, 1);
    $group->save();

    // Setting up a group content.
    $group_content = Node::Create([
      'type' => 'group_content',
      'title' => 'Group Content'
    ]);
    $group_content->save();

Bind the group and group the content:

    $membership = OgMembership::create(array('type' => 'og_membership_type_default'));
    $membership
      ->setContentId($group_content->id())
      ->setContentType('node')
      ->setGid($group->id())
      ->setEntityType('node')
      ->setFieldName(OG_AUDIENCE_FIELD)
      ->save();

    // Need to work. But the field is empty :\
    dpm(Node::Load($group_content->id())->get(OG_AUDIENCE_FIELD)->getValue());
amitaibu commented 9 years ago

@bdragon28 is that ok, or you need more pointers?

jeremyandrews commented 9 years ago

Thanks! This is very helpful. We're still getting organized on our end; @bdragon28 will reply soon.

amitaibu commented 9 years ago

:+1:

bdragon28 commented 9 years ago

Dumping some thoughts I wrote down on thursday. Most of it is probably useless but I'd like to have a record of it.


Attempting to run this, I noticed that there are significant changes to the way entity reference autocompletion is done in more recent d8. I made minimal changes to OgComplex to get it to run. It doesn't work correctly though, probably because it was written against a completely different class originally and things have moved on.

https://www.drupal.org/node/2418529 https://www.drupal.org/node/2107243

It looks like there are significantly better tools now for handling selection and access control in entityreference autocomplete fields.

I think the system might actually be robust enough to handle the autocomplete logic itself via the core code (instead of needing OG::handleAutoComplete et al) by either defining an entity reference selection plugin or by altering the entity_reference query. I will look into it further.

...

While looking through EntityReferenceFieldItemList, I note that it works with uuids. Dunno if OG needs to care about uuids or not. Probably not? .... Definitely keeping an eye on the meta issue for the entity field api... https://www.drupal.org/node/2095603

RoySegall commented 9 years ago

Can't see the use of uuid in term of OG reference but if we got it for free why not use it? And yes, the auto complete can be replaced with https://www.drupal.org/node/2418529, looks a lot more promising.