Skip to content

Commit

Permalink
Merge pull request #824 from droptica/develop
Browse files Browse the repository at this point in the history
Release 3.1.0-rc2
  • Loading branch information
grzegorz-pietrzak-droptica authored Aug 26, 2022
2 parents 694603b + 06078eb commit 9b5bf3f
Show file tree
Hide file tree
Showing 28 changed files with 516 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ jobs:
coverage: none
tools: composer, phpcs

- name: Allow phpcs composer installer
run: composer config --global --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer true

- name: Download Drupal coding standards
run: composer global require --no-progress --no-suggest --no-scripts --no-plugins --optimize-autoloader slevomat/coding-standard:^7.0 drupal/coder

Expand Down
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"bower-asset/masonry": "^4.2",
"cweagans/composer-patches": "^1.6",
"drupal/admin_toolbar": "^3.0",
"drupal/advagg": "^4.0",
"drupal/advagg": "^5.0",
"drupal/better_exposed_filters": "^5.0",
"drupal/checklistapi": "^2.0",
"drupal/colorbox": "^1.4",
Expand Down Expand Up @@ -82,8 +82,12 @@
"extra": {
"patches": {
"drupal/we_megamenu": {
"PHP 8.1 Deprecations": "https://www.drupal.org/files/issues/2022-02-24/we_megamenu_deprecated.patch",
"PHP 8.1 Deprecations p1": "https://www.drupal.org/files/issues/2022-02-24/we_megamenu_deprecated.patch",
"PHP 8.1 Depracations p2": "https://www.drupal.org/files/issues/2022-08-12/we_megamenu-3296290-5.patch",
"PHP 8.1 Compatibility": "web/profiles/contrib/droopler/patches/we_megamenu_compatibility_php81.patch"
},
"drupal/advagg": {
"PHP 8.1 Deprecations": "https://www.drupal.org/files/issues/2022-08-02/3258389-40.patch"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions config/install/advagg_js_minify.settings.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_license: false
minifier: 4
minifier: 5
ratio_max: 0.9
ratio_min: 0.1
ratio_min: 0.1
2 changes: 1 addition & 1 deletion config/install/advagg_mod.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ js_preprocess: true
prefetch: null
js_footer: null
js_remove_console_log: true
unified_multisite_dir: null
unified_multisite_dir: ''
1 change: 1 addition & 0 deletions droopler.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ dependencies:
- checklistapi:checklistapi
- colorbox:colorbox
- config_update:config_update
- ctools:ctools
- entity_reference_revisions:entity_reference_revisions
- features:features
- features:features_ui
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type: 'canonical_entities:node'
pattern: 'blog/[node:title]'
selection_criteria:
607f77ea-c917-4177-860c-31ded5df3c9a:
id: node_type
id: entity_bundle:node
bundles:
blog_post: blog_post
negate: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function d_commerce_products_list_preprocess_commerce_product(&$variables) {
/**
* Implements hook_preprocess_THEME().
*/
function d_commerce_product_preprocess_commerce_product__droopler_products__teaser(&$variables) {
function d_commerce_products_list_preprocess_commerce_product__droopler_products__teaser(&$variables) {
if (isset($variables['product']['variation_title'])) {
$variation = $variables['product']['variation_title']['#object'];
$view_builder = \Drupal::entityTypeManager()->getViewBuilder($variation->getEntityTypeId());
Expand Down
40 changes: 40 additions & 0 deletions modules/custom/d_mautic/d_mautic.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,50 @@
* Install, update, and uninstall functions for d_mautic.install.
*/

use Drupal\field\Entity\FieldConfig;

/**
* Implements hook_install().
*/
function d_mautic_install() {
Drupal::service('d_update')
->updateConfigurations('module/d_mautic', 'd_mautic.init');
}

/**
* Implements hook_uninstall().
*/
function d_mautic_uninstall() {
// Deletes node references to d_mautic paragraph after uninstalling module.
$ids = [];
$allParagraphs = \Drupal::entityTypeManager()->getStorage('paragraph')->loadMultiple();

foreach ($allParagraphs as $paragraph) {
$type = $paragraph->bundle();
if ($type === 'd_mautic') {
$ids[] = $paragraph->get('id')->getValue()[0]['value'];
}
}

$allNodes = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple();
foreach ($allNodes as $node) {
if ($node->hasField('field_page_section')) {
$page_section = $node->get('field_page_section')->getValue();
foreach ($page_section as $index => $section) {
if (in_array($section['target_id'], $ids)) {
unset($page_section[$index]);
$node->field_page_section = $page_section;
$node->save();
}
}
}
}

// Updates field configuration.
$field_instance = FieldConfig::loadByName('node', 'content_page', 'field_page_section');
$settings = $field_instance->getSetting('handler_settings');
unset($settings['target_bundles_drag_drop']['d_mautic']);
unset($settings['target_bundles']['d_mautic']);
$field_instance->setSetting('handler_settings', $settings);
$field_instance->save();
}
8 changes: 8 additions & 0 deletions modules/custom/d_p/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,11 @@ it instead. You can also use hooks to alter the widget forms:

**Note:** This method is not recommended, as long as there is no other way to alter the form elements or validate them
using the alter methods described above.

### Drush generators ###

You can use Drush to generate code for paragraphs and settings.
Please remember that the paragraph's machine name **must be the same** as module's machine name!
* `drush generate droopler-paragraph-module` - generates a module with a custom paragraph twig template. Please use your paragraph machine name as the module machine name.
* `drush generate droopler-setting-plugin` - generates a plugin with custom setting plugin.
* `drush generate droopler-setting-class-plugin` - generates a plugin with custom setting plugin (dependent on parent class plugin).
15 changes: 15 additions & 0 deletions modules/custom/d_p/drush.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
services:
droopler.paragraph_generator:
class: Drupal\d_p\Generators\ParagraphModuleGenerator
tags:
- { name: drush.generator }

droopler.setting_plugin_generator:
class: Drupal\d_p\Generators\SettingPluginGenerator
tags:
- { name: drush.generator }

droopler.setting_class_plugin_generator:
class: Drupal\d_p\Generators\SettingClassPluginGenerator
tags:
- { name: drush.generator }
59 changes: 59 additions & 0 deletions modules/custom/d_p/src/Generators/ParagraphModuleGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Drupal\d_p\Generators;

use DrupalCodeGenerator\Command\BaseGenerator;
use DrupalCodeGenerator\Utils;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;

/**
* The class that adds Droopler Paragraph generator to Drush.
*/
class ParagraphModuleGenerator extends BaseGenerator {

/**
* {@inheritdoc}
*/
protected $name = 'droopler-paragraph-module';

/**
* {@inheritdoc}
*/
protected $description = 'Generates a Droopler Paragraph module.';

/**
* {@inheritdoc}
*/
protected $alias = 'dropar';

/**
* {@inheritdoc}
*/
protected $templatePath = __DIR__;

/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output) {
$questions = Utils::moduleQuestions();
$questions['preprocess'] = new ConfirmationQuestion('Would you like to create a sample preprocess function to read paragraph settings?', TRUE);

$vars = &$this->collectVars($input, $output, $questions);
$vars['template'] = 'paragraph--' . str_replace('_', '-', $vars['machine_name']);

$this->addFile()
->path('{machine_name}.module')
->template('paragraph-module.twig');

$this->addFile()
->path('{machine_name}.info.yml')
->template('paragraph-info.twig');

$this->addFile()
->path('templates/{template}.html.twig')
->template('paragraph-template.twig');
}

}
48 changes: 48 additions & 0 deletions modules/custom/d_p/src/Generators/SettingClassPluginGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Drupal\d_p\Generators;

use DrupalCodeGenerator\Command\BaseGenerator;
use DrupalCodeGenerator\Utils;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* The class that adds Droopler Class Setting Plugin generator to Drush.
*/
class SettingClassPluginGenerator extends BaseGenerator {

/**
* {@inheritdoc}
*/
protected $name = 'droopler-setting-class-plugin';

/**
* {@inheritdoc}
*/
protected $description = 'Generates a Droopler Class Setting plugin.';

/**
* {@inheritdoc}
*/
protected $alias = 'drosec';

/**
* {@inheritdoc}
*/
protected $templatePath = __DIR__;

/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output) {
$questions = Utils::moduleQuestions() + Utils::pluginQuestions();

$vars = &$this->collectVars($input, $output, $questions);

$this->addFile()
->path('src/Plugin/ParagraphSetting/{class}.php')
->template('setting-class-plugin.twig');
}

}
47 changes: 47 additions & 0 deletions modules/custom/d_p/src/Generators/SettingPluginGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Drupal\d_p\Generators;

use DrupalCodeGenerator\Command\BaseGenerator;
use DrupalCodeGenerator\Utils;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* The class that adds Droopler Setting Plugin generator to Drush.
*/
class SettingPluginGenerator extends BaseGenerator {

/**
* {@inheritdoc}
*/
protected $name = 'droopler-setting-plugin';

/**
* {@inheritdoc}
*/
protected $description = 'Generates a Droopler Setting plugin.';

/**
* {@inheritdoc}
*/
protected $alias = 'drosep';

/**
* {@inheritdoc}
*/
protected $templatePath = __DIR__;

/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output) {
$questions = Utils::moduleQuestions() + Utils::pluginQuestions();
$vars = &$this->collectVars($input, $output, $questions);

$this->addFile()
->path('src/Plugin/ParagraphSetting/{class}.php')
->template('setting-plugin.twig');
}

}
8 changes: 8 additions & 0 deletions modules/custom/d_p/src/Generators/paragraph-info.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: {{ name }}
type: module
description: The {{ machine_name }} paragraph.
package: Paragraphs
core: 8.x
core_version_requirement: ^8 || ^9
dependencies:
- paragraphs:paragraphs
40 changes: 40 additions & 0 deletions modules/custom/d_p/src/Generators/paragraph-module.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* @file
* A module with {{ name }} paragraph.
*/
{% if preprocess %}
use Drupal\d_p\Exception\MissingConfigurationStorageFieldException;
use Drupal\d_p\Plugin\Field\FieldType\ConfigurationStorage;
{% endif %}
/**
* Implements hook_theme().
*/
function {{ machine_name }}_theme($existing, $type, $theme, $path): array {
return [
'paragraph__{{ machine_name }}' => [
'base hook' => 'paragraph',
],
];
}
{% if preprocess %}
/**
* Implements hook_preprocess_HOOK().
*/
function {{ machine_name }}_preprocess_paragraph__{{ machine_name }}(array &$variables) {
$paragraph = $variables['paragraph'];
try {
/** @var \Drupal\d_p\Plugin\Field\ConfigurationStorageFieldItemListInterface $setting_field */
$setting_field = ConfigurationStorage::getSettingsFieldFromEntity($paragraph);
$variables['foo'] = $setting_field->getSettingValue('foo');
}
catch (MissingConfigurationStorageFieldException $exception) {
\Drupal::logger('{{ machine_name }}')->error($exception->getMessage());
}
}
{% endif %}
15 changes: 15 additions & 0 deletions modules/custom/d_p/src/Generators/paragraph-preprocess.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Implements hook_preprocess_HOOK().
*/
function {{ machine_name }}_preprocess_paragraph__{{ machine_name }}(array &$variables) {
$paragraph = $variables['paragraph'];
try {
/** @var \Drupal\d_p\Plugin\Field\ConfigurationStorageFieldItemListInterface $setting_field */
$setting_field = ConfigurationStorage::getSettingsFieldFromEntity($paragraph);

$variables['foo'] = $setting_field->getSettingValue('foo');
}
catch (MissingConfigurationStorageFieldException $exception) {
\Drupal::logger('{{ machine_name }}')->error($exception->getMessage());
}
}
Loading

0 comments on commit 9b5bf3f

Please sign in to comment.