Loading bee.install +21 −1 Original line number Diff line number Diff line <?php use Drupal\Core\Config\FileStorage; use Drupal\node\Entity\NodeType; use Drupal\user\RoleInterface; /** Loading Loading @@ -94,6 +95,7 @@ function bee_uninstall() { $entityFieldManager = Drupal::service('entity_field.manager'); foreach ($node_types as $node_type) { assert($node_type instanceof NodeType); $field_names = [ 'field_availability_daily', 'field_availability_hourly', Loading @@ -111,7 +113,7 @@ function bee_uninstall() { } } Drupal::configFactory()->getEditable('node.type.' . $node_type->id())->clear('bee')->save(); $node_type->unsetThirdPartySetting('bee', 'bee')->save(); } $states = [ Loading Loading @@ -194,3 +196,21 @@ function bee_update_8006() { bee_create_booking_event_series_reference_field(); } } /** * Make sure all config settings for content types are in third party config * storage. */ function bee_update_8007() { $node_types = \Drupal::entityTypeManager()->getStorage('node_type')->loadMultiple(); foreach ($node_types as $node_type) { assert($node_type instanceof NodeType); $bee_settings = Drupal::configFactory()->get('node.type.' . $node_type->id())->get('bee'); if (empty($node_type->getThirdPartySetting('bee', 'bee')) && !empty($bee_settings)) { $node_type->setThirdPartySetting('bee', 'bee', $bee_settings)->save(); } if (!empty($bee_settings)) { Drupal::configFactory()->getEditable('node.type.' . $node_type->id())->clear('bee')->save(); } } } bee.module +21 −11 Original line number Diff line number Diff line Loading @@ -30,8 +30,9 @@ function bee_form_alter(&$form, FormStateInterface $form_state, $form_id) { if ($form_id == 'node_type_edit_form' || $form_id == 'node_type_add_form') { if (\Drupal::currentUser()->hasPermission('administer bee settings')) { $node_type = $form_state->getFormObject()->getEntity(); assert($node_type instanceof NodeType); $bee_settings = \Drupal::config('node.type.' . $node_type->id())->get('bee'); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); $form['bee'] = [ '#type' => 'details', Loading Loading @@ -117,8 +118,9 @@ function bee_form_alter(&$form, FormStateInterface $form_state, $form_id) { } elseif (preg_match('/^node_.*_edit_form$/', $form_id)) { $node = $form_state->getFormObject()->getEntity(); $bee_settings = \Drupal::config('node.type.' . $node->bundle())->get('bee'); $node_type = NodeType::load($node->bundle()); assert($node_type instanceof NodeType); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); if (isset($bee_settings['bookable']) && $bee_settings['bookable']) { $units_count = count($node->get('field_availability_' . $bee_settings['bookable_type'])->getValue()); Loading Loading @@ -253,8 +255,9 @@ function bee_node_add_more_units_submit($form, FormStateInterface $form_state) { if (is_numeric($number_units) && $number_units > 0) { $node = $form_state->getFormObject()->getEntity(); $bee_settings = \Drupal::config('node.type.' . $node->bundle())->get('bee'); $node_type = NodeType::load($node->bundle()); assert($node_type instanceof NodeType); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); $units_ids = $node->get('field_availability_' . $bee_settings['bookable_type'])->getValue(); Loading Loading @@ -308,6 +311,7 @@ function bee_node_add_more_units_ajax_callback($form, FormStateInterface $form_s */ function bee_node_type_edit_form_submit(array &$form, FormStateInterface $form_state) { $node_type = $form_state->getFormObject()->getEntity(); assert($node_type instanceof NodeType); $bee_settings = $form_state->getValue('bee'); Loading Loading @@ -383,7 +387,7 @@ function bee_node_type_edit_form_submit(array &$form, FormStateInterface $form_s } } \Drupal::configFactory()->getEditable('node.type.' . $node_type->id())->set('bee', $bee_settings)->save(); $node_type->setThirdPartySetting('bee', 'bee', $bee_settings)->save(); } else { if (isset($bee_settings['type_id'])) { Loading @@ -405,7 +409,7 @@ function bee_node_type_edit_form_submit(array &$form, FormStateInterface $form_s $bat_type->delete(); } \Drupal::configFactory()->getEditable('node.type.' . $node_type->id())->clear('bee')->save(); $node_type->unsetThirdPartySetting('bee', 'bee')->save(); } } Loading @@ -422,7 +426,9 @@ function bee_node_presave(EntityInterface $node) { * Implements hook_ENTITY_TYPE_insert(). */ function bee_node_insert(EntityInterface $node) { $bee_settings = \Drupal::config('node.type.' . $node->bundle())->get('bee'); $node_type = NodeType::load($node->bundle()); assert($node_type instanceof NodeType); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); if (isset($bee_settings['bookable']) && $bee_settings['bookable']) { if ($bee_settings['payment']) { Loading Loading @@ -450,9 +456,11 @@ function bee_node_insert(EntityInterface $node) { * Implements hook_ENTITY_TYPE_delete(). */ function bee_node_delete(EntityInterface $node) { $bee_settings = \Drupal::config('node.type.' . $node->bundle())->get('bee'); $node_type = NodeType::load($node->bundle()); assert($node_type instanceof NodeType); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); if ($node->hasField('field_availability_' . $bee_settings['bookable_type'])) { if (!empty($bee_settings['bookable_type']) && $node->hasField('field_availability_' . $bee_settings['bookable_type'])) { if ($bat_unit = $node->get('field_availability_' . $bee_settings['bookable_type'])->entity) { bat_unit_delete($bat_unit); } Loading Loading @@ -1436,7 +1444,9 @@ function bee_preprocess_bat_event_series(array &$variables) { * @return \Drupal\commerce_price\Price */ function bee_get_unit_price(Node $node, Booking $booking, DateTime $start_date, DateTime $end_date) { $bee_settings = \Drupal::config('node.type.' . $node->bundle())->get('bee'); $node_type = NodeType::load($node->bundle()); assert($node_type instanceof NodeType); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); $interval = $start_date->diff($end_date); Loading modules/bee_webform/bee_webform.module +10 −4 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; use Drupal\webform\Entity\Webform; use Drupal\webform\Entity\WebformSubmission; use RRule\RRule; Loading Loading @@ -50,12 +51,14 @@ function bee_webform_form_submit($form, FormStateInterface $form_state) { $end_date = $value['end_date']; $node = Node::load($value['node']); $node_type = NodeType::load($node->bundle()); assert($node_type instanceof NodeType); $available_units = bee_webform_get_available_units_for_node($node, $webform_submission, $bee_element_id); $events_created = []; $bee_settings = \Drupal::config('node.type.' . $node->bundle())->get('bee'); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); if ($bee_settings['bookable_type'] == 'daily') { $booked_state = bat_event_load_state_by_machine_name('bee_daily_booked'); Loading Loading @@ -188,8 +191,9 @@ function bee_webform_get_available_units($values) { $start_date = $values['start_date']; $end_date = $values['end_date']; $node = Node::load($values['node']); $bee_settings = \Drupal::config('node.type.' . $node->bundle())->get('bee'); $node_type = NodeType::load($node->bundle()); assert($node_type instanceof NodeType); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); $availability_type = $bee_settings['bookable_type']; $field_name = 'field_availability_' . $availability_type . '_target_id'; Loading Loading @@ -235,7 +239,9 @@ function bee_webform_get_available_units_for_node($node, WebformSubmission $webf $start_date = $data[$bee_element_id]['start_date']; $end_date = $data[$bee_element_id]['end_date']; $bee_settings = \Drupal::config('node.type.' . $node->bundle())->get('bee'); $node_type = NodeType::load($node->bundle()); assert($node_type instanceof NodeType); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); $drupal_units = []; foreach ($node->get('field_availability_' . $bee_settings['bookable_type']) as $unit) { Loading modules/bee_webform/src/Element/WebformBeeReservationForm.php +5 −3 Original line number Diff line number Diff line Loading @@ -29,8 +29,8 @@ class WebformBeeReservationForm extends WebformCompositeBase { foreach (array_filter($element['#content_types']) as $node_type) { $node_type = NodeType::load($node_type); $content_type_options[$node_type->id()] = $node_type->label(); $bee_settings = \Drupal::config('node.type.' . $node_type->id())->get('bee'); assert($node_type instanceof NodeType); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); if (isset($bee_settings['bookable_type'])) { $bookable_type = $bee_settings['bookable_type']; Loading Loading @@ -227,7 +227,9 @@ class WebformBeeReservationForm extends WebformCompositeBase { $nids = $query->execute(); foreach ($node_storage->loadMultiple($nids) as $node) { $bee_settings = \Drupal::config('node.type.' . $node->bundle())->get('bee'); $node_type = NodeType::load($node->bundle()); assert($node_type instanceof NodeType); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); $drupal_units = []; foreach ($node->get('field_availability_' . $bee_settings['bookable_type']) as $unit) { Loading modules/bee_webform/src/Plugin/WebformElement/WebformBeeReservationForm.php +4 −2 Original line number Diff line number Diff line Loading @@ -43,7 +43,8 @@ class WebformBeeReservationForm extends WebformCompositeBase { $options = []; foreach ($node_types as $node_type) { $bee_settings = $this->configFactory->get('node.type.' . $node_type->id())->get('bee'); assert($node_type instanceof NodeType); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); if (!empty($bee_settings['bookable'])) { $options[$node_type->id()] = $node_type->label(); Loading Loading @@ -81,7 +82,8 @@ class WebformBeeReservationForm extends WebformCompositeBase { if (count($value) > 1) { foreach ($value as $node_type) { $bee_settings = \Drupal::configFactory()->get('node.type.' . $node_type)->get('bee'); assert($node_type instanceof NodeType); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); if (isset($bee_settings['bookable_type'])) { if ($bookable_type) { Loading Loading
bee.install +21 −1 Original line number Diff line number Diff line <?php use Drupal\Core\Config\FileStorage; use Drupal\node\Entity\NodeType; use Drupal\user\RoleInterface; /** Loading Loading @@ -94,6 +95,7 @@ function bee_uninstall() { $entityFieldManager = Drupal::service('entity_field.manager'); foreach ($node_types as $node_type) { assert($node_type instanceof NodeType); $field_names = [ 'field_availability_daily', 'field_availability_hourly', Loading @@ -111,7 +113,7 @@ function bee_uninstall() { } } Drupal::configFactory()->getEditable('node.type.' . $node_type->id())->clear('bee')->save(); $node_type->unsetThirdPartySetting('bee', 'bee')->save(); } $states = [ Loading Loading @@ -194,3 +196,21 @@ function bee_update_8006() { bee_create_booking_event_series_reference_field(); } } /** * Make sure all config settings for content types are in third party config * storage. */ function bee_update_8007() { $node_types = \Drupal::entityTypeManager()->getStorage('node_type')->loadMultiple(); foreach ($node_types as $node_type) { assert($node_type instanceof NodeType); $bee_settings = Drupal::configFactory()->get('node.type.' . $node_type->id())->get('bee'); if (empty($node_type->getThirdPartySetting('bee', 'bee')) && !empty($bee_settings)) { $node_type->setThirdPartySetting('bee', 'bee', $bee_settings)->save(); } if (!empty($bee_settings)) { Drupal::configFactory()->getEditable('node.type.' . $node_type->id())->clear('bee')->save(); } } }
bee.module +21 −11 Original line number Diff line number Diff line Loading @@ -30,8 +30,9 @@ function bee_form_alter(&$form, FormStateInterface $form_state, $form_id) { if ($form_id == 'node_type_edit_form' || $form_id == 'node_type_add_form') { if (\Drupal::currentUser()->hasPermission('administer bee settings')) { $node_type = $form_state->getFormObject()->getEntity(); assert($node_type instanceof NodeType); $bee_settings = \Drupal::config('node.type.' . $node_type->id())->get('bee'); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); $form['bee'] = [ '#type' => 'details', Loading Loading @@ -117,8 +118,9 @@ function bee_form_alter(&$form, FormStateInterface $form_state, $form_id) { } elseif (preg_match('/^node_.*_edit_form$/', $form_id)) { $node = $form_state->getFormObject()->getEntity(); $bee_settings = \Drupal::config('node.type.' . $node->bundle())->get('bee'); $node_type = NodeType::load($node->bundle()); assert($node_type instanceof NodeType); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); if (isset($bee_settings['bookable']) && $bee_settings['bookable']) { $units_count = count($node->get('field_availability_' . $bee_settings['bookable_type'])->getValue()); Loading Loading @@ -253,8 +255,9 @@ function bee_node_add_more_units_submit($form, FormStateInterface $form_state) { if (is_numeric($number_units) && $number_units > 0) { $node = $form_state->getFormObject()->getEntity(); $bee_settings = \Drupal::config('node.type.' . $node->bundle())->get('bee'); $node_type = NodeType::load($node->bundle()); assert($node_type instanceof NodeType); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); $units_ids = $node->get('field_availability_' . $bee_settings['bookable_type'])->getValue(); Loading Loading @@ -308,6 +311,7 @@ function bee_node_add_more_units_ajax_callback($form, FormStateInterface $form_s */ function bee_node_type_edit_form_submit(array &$form, FormStateInterface $form_state) { $node_type = $form_state->getFormObject()->getEntity(); assert($node_type instanceof NodeType); $bee_settings = $form_state->getValue('bee'); Loading Loading @@ -383,7 +387,7 @@ function bee_node_type_edit_form_submit(array &$form, FormStateInterface $form_s } } \Drupal::configFactory()->getEditable('node.type.' . $node_type->id())->set('bee', $bee_settings)->save(); $node_type->setThirdPartySetting('bee', 'bee', $bee_settings)->save(); } else { if (isset($bee_settings['type_id'])) { Loading @@ -405,7 +409,7 @@ function bee_node_type_edit_form_submit(array &$form, FormStateInterface $form_s $bat_type->delete(); } \Drupal::configFactory()->getEditable('node.type.' . $node_type->id())->clear('bee')->save(); $node_type->unsetThirdPartySetting('bee', 'bee')->save(); } } Loading @@ -422,7 +426,9 @@ function bee_node_presave(EntityInterface $node) { * Implements hook_ENTITY_TYPE_insert(). */ function bee_node_insert(EntityInterface $node) { $bee_settings = \Drupal::config('node.type.' . $node->bundle())->get('bee'); $node_type = NodeType::load($node->bundle()); assert($node_type instanceof NodeType); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); if (isset($bee_settings['bookable']) && $bee_settings['bookable']) { if ($bee_settings['payment']) { Loading Loading @@ -450,9 +456,11 @@ function bee_node_insert(EntityInterface $node) { * Implements hook_ENTITY_TYPE_delete(). */ function bee_node_delete(EntityInterface $node) { $bee_settings = \Drupal::config('node.type.' . $node->bundle())->get('bee'); $node_type = NodeType::load($node->bundle()); assert($node_type instanceof NodeType); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); if ($node->hasField('field_availability_' . $bee_settings['bookable_type'])) { if (!empty($bee_settings['bookable_type']) && $node->hasField('field_availability_' . $bee_settings['bookable_type'])) { if ($bat_unit = $node->get('field_availability_' . $bee_settings['bookable_type'])->entity) { bat_unit_delete($bat_unit); } Loading Loading @@ -1436,7 +1444,9 @@ function bee_preprocess_bat_event_series(array &$variables) { * @return \Drupal\commerce_price\Price */ function bee_get_unit_price(Node $node, Booking $booking, DateTime $start_date, DateTime $end_date) { $bee_settings = \Drupal::config('node.type.' . $node->bundle())->get('bee'); $node_type = NodeType::load($node->bundle()); assert($node_type instanceof NodeType); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); $interval = $start_date->diff($end_date); Loading
modules/bee_webform/bee_webform.module +10 −4 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; use Drupal\webform\Entity\Webform; use Drupal\webform\Entity\WebformSubmission; use RRule\RRule; Loading Loading @@ -50,12 +51,14 @@ function bee_webform_form_submit($form, FormStateInterface $form_state) { $end_date = $value['end_date']; $node = Node::load($value['node']); $node_type = NodeType::load($node->bundle()); assert($node_type instanceof NodeType); $available_units = bee_webform_get_available_units_for_node($node, $webform_submission, $bee_element_id); $events_created = []; $bee_settings = \Drupal::config('node.type.' . $node->bundle())->get('bee'); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); if ($bee_settings['bookable_type'] == 'daily') { $booked_state = bat_event_load_state_by_machine_name('bee_daily_booked'); Loading Loading @@ -188,8 +191,9 @@ function bee_webform_get_available_units($values) { $start_date = $values['start_date']; $end_date = $values['end_date']; $node = Node::load($values['node']); $bee_settings = \Drupal::config('node.type.' . $node->bundle())->get('bee'); $node_type = NodeType::load($node->bundle()); assert($node_type instanceof NodeType); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); $availability_type = $bee_settings['bookable_type']; $field_name = 'field_availability_' . $availability_type . '_target_id'; Loading Loading @@ -235,7 +239,9 @@ function bee_webform_get_available_units_for_node($node, WebformSubmission $webf $start_date = $data[$bee_element_id]['start_date']; $end_date = $data[$bee_element_id]['end_date']; $bee_settings = \Drupal::config('node.type.' . $node->bundle())->get('bee'); $node_type = NodeType::load($node->bundle()); assert($node_type instanceof NodeType); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); $drupal_units = []; foreach ($node->get('field_availability_' . $bee_settings['bookable_type']) as $unit) { Loading
modules/bee_webform/src/Element/WebformBeeReservationForm.php +5 −3 Original line number Diff line number Diff line Loading @@ -29,8 +29,8 @@ class WebformBeeReservationForm extends WebformCompositeBase { foreach (array_filter($element['#content_types']) as $node_type) { $node_type = NodeType::load($node_type); $content_type_options[$node_type->id()] = $node_type->label(); $bee_settings = \Drupal::config('node.type.' . $node_type->id())->get('bee'); assert($node_type instanceof NodeType); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); if (isset($bee_settings['bookable_type'])) { $bookable_type = $bee_settings['bookable_type']; Loading Loading @@ -227,7 +227,9 @@ class WebformBeeReservationForm extends WebformCompositeBase { $nids = $query->execute(); foreach ($node_storage->loadMultiple($nids) as $node) { $bee_settings = \Drupal::config('node.type.' . $node->bundle())->get('bee'); $node_type = NodeType::load($node->bundle()); assert($node_type instanceof NodeType); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); $drupal_units = []; foreach ($node->get('field_availability_' . $bee_settings['bookable_type']) as $unit) { Loading
modules/bee_webform/src/Plugin/WebformElement/WebformBeeReservationForm.php +4 −2 Original line number Diff line number Diff line Loading @@ -43,7 +43,8 @@ class WebformBeeReservationForm extends WebformCompositeBase { $options = []; foreach ($node_types as $node_type) { $bee_settings = $this->configFactory->get('node.type.' . $node_type->id())->get('bee'); assert($node_type instanceof NodeType); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); if (!empty($bee_settings['bookable'])) { $options[$node_type->id()] = $node_type->label(); Loading Loading @@ -81,7 +82,8 @@ class WebformBeeReservationForm extends WebformCompositeBase { if (count($value) > 1) { foreach ($value as $node_type) { $bee_settings = \Drupal::configFactory()->get('node.type.' . $node_type)->get('bee'); assert($node_type instanceof NodeType); $bee_settings = $node_type->getThirdPartySetting('bee', 'bee'); if (isset($bee_settings['bookable_type'])) { if ($bookable_type) { Loading