-
Notifications
You must be signed in to change notification settings - Fork 16
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
Changes from 2 commits
03c0969
b267014
bd4bbcd
b17e50f
ed2f4a2
f4439c6
2ca93c8
273dd20
9f5d251
55e06bb
bc82a45
1666774
27c3fac
b263d46
a2f5eb7
70da07b
6e0b1e5
c00439b
245cc8a
ddb9d7f
ec3f732
cb4bf5a
3a6d73e
1753887
603fffe
113b402
f3c98a8
0a0f5e4
5aea9ee
becdcf7
9fce221
5ee68e9
f59e521
23a59c7
e9c7f0a
e7cad2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
og_context: | ||
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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
mapping: | ||
id: | ||
type: string | ||
label: 'ID' | ||
label: | ||
type: label | ||
label: 'Label' | ||
uuid: | ||
type: string |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, there should not be a dependency on OG UI. |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Weight 99, that seems a bit selfish :D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generated with love by Drupal console. I'll remove it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
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 |
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; | ||
|
||
} |
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; | ||
|
||
} |
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. | ||
} |
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(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
'#description' => $this->t("Label for the OG context config."), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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')); | ||
} | ||
|
||
} |
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
/** | ||
* Drupal\Core\Entity\EntityManager definition. | ||
* | ||
* @var Drupal\Core\Entity\EntityManager | ||
*/ | ||
protected $entityManager; | ||
public function __construct( | ||
EntityManager $entity_manager | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
||
} | ||
|
||
} |
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); | ||
} | ||
|
||
} |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I lost you here :) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
} | ||
|
||
} |
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); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo in file name: Enitty -> Entity There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be replaced to OgContext. Drupal console create it automatically. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is misspelled There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. => |
||
* description = @Translation("Get the group from the current entity.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
* ) | ||
*/ | ||
class Entity extends OgContextBase { | ||
|
||
} |
There was a problem hiding this comment.
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 ofnegotation
. It's probably also not necessary to prefix the config ID withogcontext
because the config system already automatically provides the prefixog_context.
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10x