Skip to content
Snippets Groups Projects
Commit 0c71b15b authored by dpi's avatar dpi
Browse files

Added method to EventMeta which removes an allowed registration type on an event.

parent 0157f2c0
No related branches found
No related tags found
No related merge requests found
...@@ -88,14 +88,10 @@ class RegistrationType extends ConfigEntityBundleBase implements RegistrationTyp ...@@ -88,14 +88,10 @@ class RegistrationType extends ConfigEntityBundleBase implements RegistrationTyp
->execute(); ->execute();
foreach ($ids as $id) { foreach ($ids as $id) {
$event = $event_storage->load($id); $event_manager
$registration_types = &$event->{EventManagerInterface::FIELD_REGISTRATION_TYPE}; ->getMeta($event_storage->load($id))
foreach ($registration_types->getValue() as $key => $value) { ->removeRegistrationType($registration_type->id())
if ($value['target_id'] == $registration_type->id()) { ->save();
$registration_types->removeItem($key);
}
}
$event->save();
} }
} }
} }
......
...@@ -66,7 +66,7 @@ interface EventManagerInterface { ...@@ -66,7 +66,7 @@ interface EventManagerInterface {
* @param \Drupal\Core\Entity\EntityInterface $entity * @param \Drupal\Core\Entity\EntityInterface $entity
* An event entity. * An event entity.
* *
* @return \Drupal\rng\EventMeta|NULL * @return \Drupal\rng\EventMetaInterface|NULL
* An event meta object. * An event meta object.
* *
* @throws \Drupal\rng\Exception\InvalidEventException * @throws \Drupal\rng\Exception\InvalidEventException
......
...@@ -140,6 +140,20 @@ class EventMeta implements EventMetaInterface { ...@@ -140,6 +140,20 @@ class EventMeta implements EventMetaInterface {
return in_array($registration_type->id(), $this->getRegistrationTypeIds()); return in_array($registration_type->id(), $this->getRegistrationTypeIds());
} }
/**
* {@inheritdoc}
*/
public function removeRegistrationType($registration_type_id) {
/** @var \Drupal\Core\Field\FieldItemListInterface $registration_types */
$registration_types = &$this->entity->{EventManagerInterface::FIELD_REGISTRATION_TYPE};
foreach ($registration_types->getValue() as $key => $value) {
if ($value['target_id'] == $registration_type_id) {
$registration_types->removeItem($key);
}
}
return $this->entity;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -94,6 +94,17 @@ interface EventMetaInterface { ...@@ -94,6 +94,17 @@ interface EventMetaInterface {
*/ */
public function registrationTypeIsValid(RegistrationTypeInterface $registration_type); public function registrationTypeIsValid(RegistrationTypeInterface $registration_type);
/**
* Removes an allowed registration type from the event.
*
* @param string $registration_type_id
* The ID of a registration_type entity.
*
* @return \Drupal\Core\Entity\EntityInterface
* The modified event.
*/
public function removeRegistrationType($registration_type_id);
/** /**
* Gets configuration for maximum permitted registrations on this event. * Gets configuration for maximum permitted registrations on this event.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment