-
Notifications
You must be signed in to change notification settings - Fork 13
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
Refactor membership module to better support plugins. Update namespac… #15
base: 8.x-1.x
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,8 @@ | |
use Drupal\entity\Revision\RevisionableContentEntityBase; | ||
use Drupal\membership\EventDispatcherTrait; | ||
use Drupal\membership\Exception\MembershipFeatureNotImplementedException; | ||
use Drupal\membership\MembershipEvent; | ||
use Drupal\membership\MembershipEvents; | ||
use Drupal\membership\Event\MembershipEvent; | ||
use Drupal\membership\Event\MembershipEvents; | ||
use Drupal\user\UserInterface; | ||
|
||
/** | ||
|
@@ -148,9 +148,10 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { | |
->setDescription(t('The Membership type/bundle.')) | ||
->setSetting('target_type', 'membership_type') | ||
->setRequired(TRUE); | ||
|
||
$fields['user_id'] = BaseFieldDefinition::create('entity_reference') | ||
->setLabel(t('Authored by')) | ||
->setDescription(t('The owner of the Membership entity.')) | ||
->setLabel(t('Primary user')) | ||
->setDescription(t('The owner of the Membership.')) | ||
->setRevisionable(TRUE) | ||
->setSetting('target_type', 'user') | ||
->setSetting('handler', 'default') | ||
|
@@ -173,6 +174,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { | |
)) | ||
->setDisplayConfigurable('form', TRUE) | ||
->setDisplayConfigurable('view', TRUE); | ||
|
||
$fields['data'] = BaseFieldDefinition::create('map') | ||
->setLabel(t('Data')) | ||
->setReadOnly(TRUE) | ||
|
@@ -200,6 +202,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { | |
->setDisplayConfigurable('view', TRUE) | ||
->setRevisionable(TRUE) | ||
->setSetting('workflow_callback', ['\Drupal\membership\Entity\Membership', 'getWorkflowId']); | ||
|
||
$fields['provider'] = BaseFieldDefinition::create('membership_provider_id') | ||
->setLabel('Provider plugin/remote ID') | ||
->setDisplayConfigurable('form', false) | ||
|
@@ -225,6 +228,7 @@ public function preSave(EntityStorageInterface $storage) { | |
if ($this->isExpired()) { | ||
$this->getEventDispatcher()->dispatch(MembershipEvents::EXPIRE, $event); | ||
} | ||
$this->setRevisionLogMessage($this->t('State changed: '.$this->state->getValue())); | ||
} | ||
parent::preSave($storage); | ||
} | ||
|
@@ -248,6 +252,15 @@ public function postCreate(EntityStorageInterface $storage) { | |
parent::postCreate($storage); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
function postSave(EntityStorageInterface $storage, $update = TRUE) { | ||
$event = new MembershipEvent($this); | ||
$this->getEventDispatcher()->dispatch(MembershipEvents::UPDATED, $event); | ||
parent::postSave($storage, $update); | ||
|
||
} | ||
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 we really need to throw our own event here? State Machine module emits an event on state changes, and core already has In the same vein I think we can back out 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. Ok. Still haven't gotten to the state change events yet -- probably will be in there today or tomorrow -- so I haven't seen how state_machine handles this. I was trying to avoid hook_entity_insert() and hook_entity_update() and go with a more OO approach, and this looked like the best way... What's your sense of preference going forward -- symfony events vs hooks? I would prefer events, just because that's a pattern I use on a bunch of projects (and never particularly liked hooks). But I can live with a hook here if they aren't going to be deprecated... I was surprised to not find any decorator or observers related to the Entity Manager to supersede these hooks... |
||
|
||
/** | ||
* @inheritDoc | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,32 +15,39 @@ interface MembershipTermInterface extends ContentEntityInterface, EntityChanged | |
|
||
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 interface belongs in 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. Yeah can move that... |
||
// Add get/set methods for your configuration properties here. | ||
|
||
|
||
/** | ||
* Gets the Membership term type. | ||
* Gets the membership for a term | ||
* | ||
* @return string | ||
* The Membership term type. | ||
* @return Membership | ||
* The membership entity | ||
*/ | ||
public function getType(); | ||
public function getMembership(); | ||
|
||
/** | ||
* Gets the Membership term name. | ||
* Set a membership on a term. | ||
* | ||
* @return string | ||
* Name of the Membership term. | ||
* @param \Drupal\membership\Entity\MembershipInterface $membership | ||
* | ||
* @return \Drupal\membership\Entity\MembershipTermInterface | ||
* The called Membership term. | ||
*/ | ||
public function getName(); | ||
|
||
public function setMembership(MembershipInterface $membership); | ||
/** | ||
* Sets the Membership term name. | ||
* Gets the membership id for a term | ||
* | ||
* @param string $name | ||
* The Membership term name. | ||
* @return integer | ||
* The membership entity_id | ||
*/ | ||
public function getMembershipId(); | ||
|
||
/** | ||
* Gets the Membership term type. | ||
* | ||
* @return \Drupal\membership\Entity\MembershipTermInterface | ||
* The called Membership term entity. | ||
* @return string | ||
* The Membership term type. | ||
*/ | ||
public function setName($name); | ||
public function getType(); | ||
|
||
/** | ||
* Gets the Membership term creation timestamp. | ||
|
@@ -61,26 +68,6 @@ public function getCreatedTime(); | |
*/ | ||
public function setCreatedTime($timestamp); | ||
|
||
/** | ||
* Returns the Membership term published status indicator. | ||
* | ||
* Unpublished Membership term are only visible to restricted users. | ||
* | ||
* @return bool | ||
* TRUE if the Membership term is published. | ||
*/ | ||
public function isPublished(); | ||
|
||
/** | ||
* Sets the published status of a Membership term. | ||
* | ||
* @param bool $published | ||
* TRUE to set this Membership term to published, FALSE to set it to unpublished. | ||
* | ||
* @return \Drupal\membership\Entity\MembershipTermInterface | ||
* The called Membership term entity. | ||
*/ | ||
public function setPublished($published); | ||
|
||
/** | ||
* Returns the Membership Type (bundle) that this membership term is associated with. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,15 @@ public function setWorkflowId($workflow_id); | |
*/ | ||
public function getMembershipType(); | ||
|
||
/** | ||
* @return string | ||
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. Same as above; belongs in 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. ok |
||
*/ | ||
public function getTermLength(); | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getGracePeriod(); | ||
/** | ||
* @param string $membership_type | ||
* @return string | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,13 @@ class MembershipType extends ConfigEntityBase implements MembershipTypeInterface | |
*/ | ||
protected $workflow; | ||
|
||
/** | ||
* The processor plugin string ID. | ||
* | ||
* @var string | ||
*/ | ||
protected $processor_plugin_id; | ||
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. What's with the "processor plugin"? I'm not sure what this is? 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 was/is an instance of \Drupal\membership\Plugin\MembershipProviderInterface. I was thinking it would be useful to have some membership types control the plugin for their membership instances. However, after getting something actually working, I reached the conclusion you were correct, it needs to be on the Membership instance, not on MembershipType. Will remove. |
||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
|
@@ -81,6 +88,20 @@ public function setWorkflowId($workflow_id) { | |
return $this; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getProcessorPlugin() { | ||
// TODO: Implement getProcessorPlugin() method. | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function setProcessorPluginId($processor_plugin_id) { | ||
// TODO: Implement setProcessorPluginId() method. | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,9 @@ public function buildForm(array $form, FormStateInterface $form_state) { | |
/* @var $entity \Drupal\membership\Entity\Membership */ | ||
$form = parent::buildForm($form, $form_state); | ||
|
||
// Hide revision message and revision fields... | ||
$form['revision_information']['#access'] = FALSE; | ||
$form['revision_log_message']['#access'] = FALSE; | ||
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. Is there a reason to hide these? I see your logic for adding a default message on save, however I think there's a use case for revision notes by the admin? 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. Hi, There's certainly a use case for admins leaving comments, should probably change this to a permission. It's quite confusing with these fields visible, though, and for some reason it's showing up twice. For now was just hiding to make this usable. |
||
return $form; | ||
} | ||
|
||
|
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.
"Primary" implies some precedence of multiple users... how about just "User"?
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.
Ok, will change.
We do plan to support multiple users per membership, that is a requirement for several of our clients. So this will essentially be the author who can "change own" and add/remove users to a membership if more than one is allowed. We will want the API to support this, without requiring it...