Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

WIP: First sketch of the OG context module. #252

Merged
merged 36 commits into from
Nov 8, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
03c0969
First sketch of the OG context module.
Jul 17, 2016
b267014
Adding files.
Jul 19, 2016
bd4bbcd
Moving OG context to OG core.
Jul 22, 2016
b17e50f
Commit more work.
Jul 22, 2016
ed2f4a2
Iterate over plugins easily.
Jul 22, 2016
f4439c6
Get list of plugins by a logic you desire.
Jul 22, 2016
2ca93c8
Minor fixes.
Jul 22, 2016
273dd20
Get the plugins in the right order.
Jul 22, 2016
9f5d251
Get the group from the url.
Jul 22, 2016
55e06bb
Pushing work.
Jul 22, 2016
bc82a45
Get the group from a group content.
Jul 22, 2016
1666774
Get all the groups.
Jul 22, 2016
27c3fac
Remove a line in the end of the file.
Jul 23, 2016
b263d46
My own CR fixes.
Jul 23, 2016
a2f5eb7
Adding some tests.
Jul 24, 2016
70da07b
Merge master
Jul 24, 2016
6e0b1e5
CS fixes(hope)
Jul 24, 2016
c00439b
More CS.
Jul 24, 2016
245cc8a
she's into a typical riff.
Jul 24, 2016
ddb9d7f
Hmm...
Jul 24, 2016
ec3f732
Return the first group for now.
Jul 26, 2016
cb4bf5a
Keep entity as the only plugin.
Jul 27, 2016
3a6d73e
Testing the context it self.
Jul 27, 2016
1753887
Rename the plugin to GroupResolver.
Aug 6, 2016
603fffe
Refactor the entity name [skip ci]
Aug 6, 2016
113b402
More renaming [skip ci]
Aug 6, 2016
f3c98a8
More renaming [skip ci]
Aug 6, 2016
0a0f5e4
Down with renaming.
Aug 6, 2016
5aea9ee
Fix code sniffer.
Aug 6, 2016
becdcf7
Merge branch '8.x-1.x' into 242
Aug 6, 2016
9fce221
Fix tests.
Aug 6, 2016
5ee68e9
Fix conflicts
Aug 26, 2016
f59e521
Extend from the correct class and fix a service.
Aug 26, 2016
23a59c7
Make CS happy.
Aug 26, 2016
e9c7f0a
Adding test.
Aug 27, 2016
e7cad2d
Merge remote-tracking branch 'origin/8.x-1.x' into 242
pfrenssen Sep 14, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
og_context:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a typo here: neogation instead of negotation. It's probably also not necessary to prefix the config ID with ogcontext because the config system already automatically provides the prefix og_context..

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10x

12 changes: 12 additions & 0 deletions modules/og_context/config/schema/og_context_config.schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
og_context.og_context_config.*:
type: config_entity
label: 'OG context config config'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has the word "config" twice in the label :) Also not needed to prefix the config ID with og_context_.

mapping:
id:
type: string
label: 'ID'
label:
type: label
label: 'Label'
uuid:
type: string
7 changes: 7 additions & 0 deletions modules/og_context/og_context.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: OG context
type: module
description: Get a group from a viewed page.
core: 8.x
package: OG
dependencies:
- og_ui
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this would have a strict dependency on OG UI?

I'm asking because in our project we do not need OG UI, but we will need OG Context, so it would be a pity if we have to enable an unused module for it.

This is probably to allow some configuration in the UI. We can make this optional as well, only unlock the UI when OG UI is enabled, or make an og_context_ui module :D

For me it is fine to keep it like this for now and tackle it later.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We thought about it a bit this morning and we might don't need this as an external module. OG context is on of the strogest module in the OG stack. Why not put in inside the core?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me it's fine! I think this is good core functionality.

For example, I have a block that shows some options that depend on the user's role in the current group. I cannot set the cache context without knowing which group is being shown on the page. To me setting the correct cacheability metadata sounds like core functionality.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, there should not be a dependency on OG UI.

7 changes: 7 additions & 0 deletions modules/og_context/og_context.links.menu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# OG context config menu items definition
entity.og_context_config.collection:
title: 'OG context'
route_name: entity.og_context_config.collection
description: 'Manage order of OG context plugins.'
parent: og_ui.admin_index
weight: 99
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weight 99, that seems a bit selfish :D

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generated with love by Drupal console. I'll remove it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

4 changes: 4 additions & 0 deletions modules/og_context/og_context.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
services:
plugin.manager.og.context:
class: Drupal\og_context\Plugin\OgContextManager
parent: default_plugin_manager
34 changes: 34 additions & 0 deletions modules/og_context/src/Annotation/OgContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Drupal\og_context\Annotation;

use Drupal\Component\Annotation\Plugin;

/**
* Defines a OG context item annotation object.
*
* @see \Drupal\og_context\Plugin\OgContextManager
* @see plugin_api
*
* @Annotation
*/
class OgContext extends Plugin {


/**
* The plugin ID.
*
* @var string
*/
public $id;

/**
* The label of the plugin.
*
* @var \Drupal\Core\Annotation\Translation
*
* @ingroup plugin_translatable
*/
public $label;

}
47 changes: 47 additions & 0 deletions modules/og_context/src/Entity/OgContextConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Drupal\og_context\Entity;

use Drupal\Core\Config\Entity\ConfigEntityBase;

/**
* Defines the OG context config entity.
*
* @ConfigEntityType(
* id = "og_context_config",
* label = @Translation("OG context config"),
* handlers = {
* "list_builder" = "Drupal\og_context\OgContextConfigListBuilder",
* "route_provider" = {
* "html" = "Drupal\og_context\OgContextConfigHtmlRouteProvider",
* },
* },
* config_prefix = "og_context_config",
* admin_permission = "administer site configuration",
* entity_keys = {
* "id" = "id",
* "label" = "label",
* "uuid" = "uuid"
* },
* links = {
* "collection" = "/admin/config/og/og_context_config"
* }
* )
*/
class OgContextConfig extends ConfigEntityBase implements OgContextConfigInterface {

/**
* The OG context config ID.
*
* @var string
*/
protected $id;

/**
* The OG context config label.
*
* @var string
*/
protected $label;

}
13 changes: 13 additions & 0 deletions modules/og_context/src/Entity/OgContextConfigInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Drupal\og_context\Entity;

use Drupal\Core\Config\Entity\ConfigEntityInterface;

/**
* Provides an interface for defining OG context config entities.
*/
interface OgContextConfigInterface extends ConfigEntityInterface {

// Add get/set methods for your configuration properties here.
}
67 changes: 67 additions & 0 deletions modules/og_context/src/Form/OgContextConfigForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Drupal\og_context\Form;

use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Form\FormStateInterface;

/**
* Class OgContextConfigForm.
*
* @package Drupal\og_context\Form
*/
class OgContextConfigForm extends EntityForm {

/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);

$og_context_config = $this->entity;
$form['label'] = array(
'#type' => 'textfield',
'#title' => $this->t('Label'),
'#maxlength' => 255,
'#default_value' => $og_context_config->label(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Xss::filter()

'#description' => $this->t("Label for the OG context config."),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

" => '

'#required' => TRUE,
);

$form['id'] = array(
'#type' => 'machine_name',
'#default_value' => $og_context_config->id(),
'#machine_name' => array(
'exists' => '\Drupal\og_context\Entity\OgContextConfig::load',
),
'#disabled' => !$og_context_config->isNew(),
);

/* You will need additional form elements for your custom properties. */

return $form;
}

/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
$og_context_config = $this->entity;
$status = $og_context_config->save();

switch ($status) {
case SAVED_NEW:
drupal_set_message($this->t('Created the %label OG context config.', [
'%label' => $og_context_config->label(),
]));
break;

default:
drupal_set_message($this->t('Saved the %label OG context config.', [
'%label' => $og_context_config->label(),
]));
}
$form_state->setRedirectUrl($og_context_config->urlInfo('collection'));
}

}
58 changes: 58 additions & 0 deletions modules/og_context/src/Form/OgContextNeogation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Drupal\og_context\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityManager;

/**
* Class OgContextNeogation.
*
* @package Drupal\og_context\Form
*/
class OgContextNeogation extends FormBase {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Neogation/Negotiation/g


/**
* Drupal\Core\Entity\EntityManager definition.
*
* @var Drupal\Core\Entity\EntityManager
*/
protected $entityManager;
public function __construct(
EntityManager $entity_manager
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks scary 😉

) {
$this->entityManager = $entity_manager;
}

public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager')
);
}


/**
* {@inheritdoc}
*/
public function getFormId() {
return 'og_context_neogation';
}

/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {

return $form;
}

/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {

}

}
25 changes: 25 additions & 0 deletions modules/og_context/src/OgContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Drupal\og_context;

use Drupal\og_context\Plugin\OgContextBase;
use Drupal\og_context\Plugin\OgContextManager;

class OgContext {

/**
* Get a instance of an OG context plugin.
*
* @param $plugin
* The plugin ID.
*
* @return OgContextBase
*/
static public function getPlugin($plugin) {
/** @var OgContextManager $service */
$service = \Drupal::service('plugin.manager.og.context');

return $service->createInstance($plugin);
}

}
59 changes: 59 additions & 0 deletions modules/og_context/src/OgContextConfigHtmlRouteProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Drupal\og_context;

use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
use Symfony\Component\Routing\Route;

/**
* Provides routes for OG context config entities.
*
* @see Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
* @see Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
*/
class OgContextConfigHtmlRouteProvider extends AdminHtmlRouteProvider {

/**
* {@inheritdoc}
*/
public function getRoutes(EntityTypeInterface $entity_type) {
$collection = parent::getRoutes($entity_type);

$entity_type_id = $entity_type->id();

if ($collection_route = $this->getCollectionRoute($entity_type)) {
$collection->add("entity.{$entity_type_id}.collection", $collection_route);
}

return $collection;
}

/**
* Gets the collection route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getCollectionRoute(EntityTypeInterface $entity_type) {
if ($entity_type->hasLinkTemplate('collection') && $entity_type->hasListBuilderClass()) {
$entity_type_id = $entity_type->id();
$route = new Route($entity_type->getLinkTemplate('collection'));
$route
->setDefaults([
'_entity_list' => $entity_type_id,
// Make sure this is not a TranslatableMarkup object as the
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I lost you here :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generated with love by Drupal console. This going to trash can any way.

// TitleResolver translates this string again.
'_title' => (string) $entity_type->getLabel(),
])
->setRequirement('_permission', $entity_type->getAdminPermission())
->setOption('_admin_route', TRUE);

return $route;
}
}

}
32 changes: 32 additions & 0 deletions modules/og_context/src/OgContextConfigListBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Drupal\og_context;

use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;

/**
* Provides a listing of OG context config entities.
*/
class OgContextConfigListBuilder extends ConfigEntityListBuilder {

/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['label'] = $this->t('OG context config');
$header['id'] = $this->t('Machine name');
return $header + parent::buildHeader();
}

/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity->label();
$row['id'] = $entity->id();
// You probably want a few more properties here...
return $row + parent::buildRow($entity);
}

}
16 changes: 16 additions & 0 deletions modules/og_context/src/Plugin/OgContext/Enitty.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
Copy link

@zerolab zerolab Jul 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo in file name: Enitty -> Entity

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be replaced to OgContext. Drupal console create it automatically.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is misspelled Enitty instead of Entity.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concurrent review :D


namespace Drupal\og_context\Plugin\OgContext;

use Drupal\og_context\Plugin\OgContextBase;

/**
* @OgContext(
* id = "entity",
* title = "Entity base",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> Entity

* description = @Translation("Get the group from the current entity.")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get the group from the current entity, by checking if it is a group or a group content entity.

* )
*/
class Entity extends OgContextBase {

}
Loading