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

Added field_show_time. #46

Merged
merged 3 commits into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -8,6 +8,7 @@ dependencies:
- field.field.paragraph.event_details.field_paragraph_event_price_to
- field.field.paragraph.event_details.field_paragraph_link
- field.field.paragraph.event_details.field_paragraph_location
- field.field.paragraph.event_details.field_show_time
- paragraphs.paragraphs_type.event_details
module:
- address
Expand All @@ -19,6 +20,13 @@ targetEntityType: paragraph
bundle: event_details
mode: default
content:
field_show_time:
weight: -10
settings:
display_label: true
third_party_settings: { }
type: boolean_checkbox
region: content
field_event_requirements:
weight: 4
settings:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
langcode: en
status: true
dependencies:
config:
- field.storage.paragraph.field_show_time
- paragraphs.paragraphs_type.event_details
id: paragraph.event_details.field_show_time
field_name: field_show_time
entity_type: paragraph
bundle: event_details
label: 'Display time'
description: ''
required: false
translatable: false
default_value:
-
value: 1
default_value_callback: ''
settings:
on_label: 'On'
off_label: 'Off'
field_type: boolean
17 changes: 17 additions & 0 deletions config/install/field.storage.paragraph.field_show_time.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
langcode: en
status: true
dependencies:
module:
- paragraphs
id: paragraph.field_show_time
field_name: field_show_time
entity_type: paragraph
type: boolean
settings: { }
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
2 changes: 2 additions & 0 deletions tide_event.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ config_devel:
- field.field.node.event.field_show_social_sharing
- field.field.node.event.field_tags
- field.field.node.event.field_topic
- field.field.paragraph.event_details.field_show_time
- field.field.paragraph.event_details.field_event_requirements
- field.field.paragraph.event_details.field_paragraph_date_range
- field.field.paragraph.event_details.field_paragraph_event_price_from
Expand All @@ -52,6 +53,7 @@ config_devel:
- field.storage.paragraph.field_event_requirements
- field.storage.paragraph.field_paragraph_event_price_from
- field.storage.paragraph.field_paragraph_event_price_to
- field.storage.paragraph.field_show_time
- node.type.event
- paragraphs.paragraphs_type.event_details
- simple_sitemap.bundle_settings.node.event
Expand Down
53 changes: 53 additions & 0 deletions tide_event.install
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

use Drupal\Core\Session\AccountInterface;
use Drupal\paragraphs\Entity\Paragraph;
use Drupal\field\Entity\FieldConfig;
use Drupal\search_api\Item\Field;
use Drupal\user\Entity\Role;
Expand Down Expand Up @@ -334,3 +335,55 @@ function tide_event_update_8006() {
$field->save();
}
}

/**
* Adds field_show_time.
*/
function tide_event_update_8007() {
module_load_include('inc', 'tide_core', 'includes/helpers');
$config_location = [drupal_get_path('module', 'tide_event') . '/config/install'];
_tide_import_single_config('field.storage.paragraph.field_show_time', $config_location);
_tide_import_single_config('field.field.paragraph.event_details.field_show_time', $config_location);
_tide_import_single_config('core.entity_form_display.paragraph.event_details.default', $config_location);
}

/**
* Set default value of field_show_time for existing events.
*/
function tide_event_update_8008(&$sandbox) {
$new_field = 'field_show_time';

if (!isset($sandbox['total'])) {
$count = \Drupal::entityQuery('paragraph')
->condition('type', 'event_details')
->notExists($new_field)
->count()
->execute();
$sandbox['total'] = $count;
$sandbox['current'] = 0;
$sandbox['processed'] = 0;
$sandbox['#finished'] = $count ? 0 : 1;
}

$batch_size = 50;
$ids = \Drupal::entityQuery('paragraph')
->condition('type', 'event_details')
->notExists($new_field)
->condition('id', $sandbox['current'], '>')
->sort('id', 'ASC')
->range(0, $batch_size)
->execute();

foreach ($ids as $id) {
$sandbox['current'] = $id;
$paragraph = Paragraph::load($id);
if ($paragraph && $paragraph->hasField($new_field)) {
$paragraph->set($new_field, TRUE);
$paragraph->setNewRevision(FALSE);
$paragraph->save();
}
$sandbox['processed']++;
}

$sandbox['#finished'] = ($sandbox['processed'] / $sandbox['total']);
}