Skip to content

Text field search #35

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

Open
wants to merge 23 commits into
base: 4.0
Choose a base branch
from
Open
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
86 changes: 60 additions & 26 deletions .github/workflows/drupal-tests-and-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,10 @@ jobs:
strategy:
fail-fast: false
matrix:
drupal-core: ['9.4.x', '9.5.x', '10.0.x', '10.1.x']
php-version: ['8.0', '8.1', '8.2']
drupal-core: ['10.0.x', '10.1.x']
php-version: ['8.1', '8.2']
mariadb-version: ['10.4', '10.6']
exclude:
-
drupal-core: '9.4.x'
php-version: '8.2'
mariadb-version: '10.4'
-
drupal-core: '9.4.x'
php-version: '8.2'
mariadb-version: '10.6'
-
drupal-core: '9.5.x'
php-version: '8.2'
mariadb-version: '10.4'
-
drupal-core: '9.5.x'
php-version: '8.2'
mariadb-version: '10.6'
-
drupal-core: '10.0.x'
php-version: '8.0'
Expand Down Expand Up @@ -177,7 +161,7 @@ jobs:
working-directory: ${{ env.DRUPAL_ROOT }}
run: |
composer config --no-plugins allow-plugins.oomphinc/composer-installers-extender true
composer config repositories.0 path $GITHUB_WORKSPACE
composer config repositories.$DRUPAL_MODULE_NAME '{"type": "path", "url": "$GITHUB_WORKSPACE", "options": {"symlink": true}}'
composer config extra.installer-paths
composer config --json extra.installer-types '["custom-drupal-module"]'
composer config --json --merge extra.installer-paths '{"modules/bluecadet/{$name}": ["type:custom-drupal-module"]}'
Expand All @@ -201,6 +185,7 @@ jobs:
run: |
composer config --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer require --dev "drupal/coder"
composer require bluecadet/bc_composer_ci_tools:^1.0

# Install Drupal using minimal installation profile and enable the module.
- name: Install Drupal
Expand All @@ -214,14 +199,26 @@ jobs:
working-directory: ${{ env.DRUPAL_ROOT }}
continue-on-error: true
run: |
vendor/bin/phpcs -s --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt --ignore=node_modules,bower_components,vendor,dist --exclude=Drupal.InfoFiles.AutoAddedKeys --colors $MODULE_FOLDER
vendor/bin/phpcs -s --standard=DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt --ignore=node_modules,bower_components,vendor,dist --exclude=Drupal.InfoFiles.AutoAddedKeys --colors $MODULE_FOLDER
vendor/bin/phpcs --config-set ignore_warnings_on_exit 1
vendor/bin/phpcs --config-set ignore_errors_on_exit 1
vendor/bin/phpcs -s --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt --ignore=node_modules,bower_components,vendor,dist --exclude=Drupal.InfoFiles.AutoAddedKeys --report=Bluecadet\\PHPCS\\Report\\Markdown $MODULE_FOLDER
vendor/bin/phpcs -s --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt --ignore=node_modules,bower_components,vendor,dist --exclude=Drupal.InfoFiles.AutoAddedKeys --report=Bluecadet\\PHPCS\\Report\\Markdown $MODULE_FOLDER >> styling_report.md
vendor/bin/phpcs -s --standard=DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,json --ignore=node_modules,bower_components,vendor,dist --exclude=Drupal.InfoFiles.AutoAddedKeys --report=Bluecadet\\PHPCS\\Report\\Markdown $MODULE_FOLDER >> styling_report.md

- name: Run Drupal-Check
working-directory: ${{ env.DRUPAL_ROOT }}
continue-on-error: true
run: |
php vendor/bin/drupal-check $MODULE_FOLDER --drupal-root ${{ env.DRUPAL_ROOT }}
# npm i -g github:10up/phpcs-json-to-md
# phpcs-json-to-md --path ./styling_report1.json --output ./styling_report1.md
# cat styling_report1.md >> $GITHUB_STEP_SUMMARY

PHPCS_REPORT=`cat styling_report.md`
echo "PHPCS_REPORT=$PHPCS_REPORT" >> $GITHUB_ENV
echo $PHPCS_REPORT >> $GITHUB_STEP_SUMMARY
# echo "### Hello world! :rocket:" >> $GITHUB_STEP_SUMMARY

# - name: Run Drupal-Check
# working-directory: ${{ env.DRUPAL_ROOT }}
# continue-on-error: true
# run: |
# php vendor/bin/drupal-check $MODULE_FOLDER --drupal-root ${{ env.DRUPAL_ROOT }}

- name: Start Drush webserver and chromedriver
working-directory: ${{ env.DRUPAL_ROOT }}
Expand Down Expand Up @@ -263,3 +260,40 @@ jobs:
continue-on-error: true
run: |
vendor/bin/phpunit --bootstrap $DRUPAL_ROOT/core/tests/bootstrap.php -c $MODULE_FOLDER/phpunit.xml $MODULE_FOLDER

# - uses: actions/github-script@v6
# id: get_issue_number
# with:
# script: |
# if (context.issue.number) {
# // Return issue number if present
# return context.issue.number;
# } else {
# // Otherwise return issue number from commit
# return (
# await github.rest.repos.listPullRequestsAssociatedWithCommit({
# commit_sha: context.sha,
# owner: context.repo.owner,
# repo: context.repo.repo,
# })
# ).data[0].number;
# }
# result-encoding: string

# - uses: actions/github-script@v6
# env:
# prn: ${{ steps.get_issue_number.outputs.result }}
# PHPCS_REPORT: ${{ env.PHPCS_REPORT }}
# with:
# script: |
# console.log(context)
# console.log(process.env)

# const { prn, PHPCS_REPORT } = process.env

# github.rest.issues.createComment({
# issue_number: 35,
# owner: context.repo.owner,
# repo: context.repo.repo,
# body: 'hello world'
# })
241 changes: 241 additions & 0 deletions ImageStyleGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
<?php

namespace Drupal\bluecadet_utilities\Form;

use Drupal\bluecadet_utilities\DrupalStateTrait;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Link;
use Drupal\Core\Messenger\MessengerTrait;
use Drupal\Core\Render\Markup;
use Drupal\Core\Url;
use Drupal\image\Entity\ImageStyle;

/**
* Bluecadet Utility Settings Form.
*/
class ImageStyleGenerator extends FormBase {

use DrupalStateTrait;
use MessengerTrait;

/**
* Drupal Module Handler.
*
* @var \Drupal\Core\Extension\ModuleHandler
*/
private $moduleHandler;

/**
* Get module handler.
*/
private function moduleHandler() {
if (!$this->moduleHandler) {
$this->moduleHandler = \Drupal::service('module_handler'); // phpcs:ignore
}

return $this->moduleHandler;
}

/**
* {@inheritdoc}
*/
public function getFormId() {
return 'bcu_img_style_generator';
}

/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// phpcs:ignore
// $this->drupalState()->delete(BCU_IMG_GEN_STATE);

$settings = $this->drupalState()->get(BCU_IMG_GEN_STATE, NULL);

if (is_null($settings)) {

$message = "Please create ";
$message .= Link::fromTextAndUrl("Size Settings", Url::fromRoute("bluecadet_utilities.image_style_generator_settings"))->toString();
$message .= ".";

$message = Markup::create($message);

$this->messenger()->addWarning($message, FALSE);
return;
}

$form['#tree'] = TRUE;

$sizes_preview = [
'#theme' => 'item_list',
'#items' => [],
];
foreach ($settings['sizes'] as $size) {
$sizes_preview['#items'][] = $size['label'] . ": " . $size['size'] . "px";
}

$form['preview'] = [
'#markup' => \Drupal::service('renderer')->render($sizes_preview),
];

$form['msg'] = [
'#markup' => '<p>Set the Aspect ratio.</p>',
];
$form['width'] = [
'#type' => 'number',
'#title' => 'Width',
'#description' => $this->t('Width of the ratio'),
'#prefix' => "<div class=\"aspect-container\">",
];

$form['height'] = [
'#type' => 'number',
'#title' => 'Height',
'#description' => $this->t('Height of the ratio'),
'#suffix' => "</div>",
];

$options = [
'image_scale_and_crop' => "Scale & Crop",
];

// Check for Focal Point module.
if ($this->moduleHandler()->moduleExists('focal_point')) {
$options["focal_point_scale_and_crop"] = "Focal Point";
}

// phpcs:disable
// Check for image_widget_crop module.
// if ($this->moduleHandler()->moduleExists('image_widget_crop')) {
// $options["crop_crop"] = "Image Widget Crop";
// }
// phpcs:enable

$form['image_style_effects_variations'] = [
'#type' => 'checkboxes',
'#title' => 'Image Style variations',
'#description' => $this->t('Choose the variation you would like to create for each image style.'),
'#options' => $options,
];

// phpcs:disable
// if ($this->moduleHandler()->moduleExists('image_widget_crop')) {

// $cropTypeStorage = \Drupal::service('entity_type.manager')->getStorage('crop_type');

// $crop_options = [];
// foreach ($cropTypeStorage->loadMultiple() as $c_id => $crop) {
// $crop_options[$c_id] = $crop->label();
// }

// $form['image_crop'] = [
// '#type' => 'select',
// '#title' => 'Which Crop',
// '#description' => $this->t('Choose the crop.'),
// '#options' => $crop_options,
// ];
// }
// phpcs:enable

// Actions.
$form['actions'] = ['#type' => 'actions'];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Create Image styles'),
];

return $form;
}

/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state->getValues();
$settings = $this->drupalState()->get(BCU_IMG_GEN_STATE, NULL);

$responses = [];

foreach ($values['image_style_effects_variations'] as $key => $val) {
if ($val) {
foreach ($settings['sizes'] as $size) {
$label = $size['label'];
$w_size = $size['size'];

$machinename = $this->getMachineName($values['width'] . "x" . $values['height'] . "__" . $key . "__" . $label);

if (ImageStyle::load($machinename) == NULL) { // phpcs:ignore
$image_style = ImageStyle::create([
'status' => TRUE,
'name' => $machinename,
'label' => $machinename,
]);

$image_style->addImageEffect([
'id' => $key,
'weight' => 1,
'data' => [
'width' => $w_size,
'height' => ceil($w_size * $values['height'] / $values['width']),
],
]);

$image_style->addImageEffect([
'id' => 'image_convert',
'weight' => 2,
'data' => [
'format' => "webp",
'quality' => '92',
],
]);

$image_style->save();

$responses[] = $machinename;
}
else {
$this->messenger()->addWarning("Already exists: " . $machinename);
}
}
}
}

$message_render = [
'#theme' => 'item_list',
'#items' => $responses,
];
// phpcs:ignore
$msg = Markup::create("The following Image Styles have been created: " . \Drupal::service('renderer')->render($message_render));

$this->messenger()->addMessage($msg);
}

/**
* Generates a machine name from a string.
*
* This is basically the same as what is done in
* \Drupal\Core\Block\BlockBase::getMachineNameSuggestion() and
* \Drupal\system\MachineNameController::transliterate(), but it seems
* that so far there is no common service for handling this.
*
* from: https://zgadzaj.com/development/php/drupal/8/how-to-generate-a-machine-name-in-drupal-8
*
* @param string $string
*
* @return string
*
* @see \Drupal\Core\Block\BlockBase::getMachineNameSuggestion()
* @see \Drupal\system\MachineNameController::transliterate()
*/
protected function getMachineName($string) {
$transliterated = \Drupal::transliteration()->transliterate($string, LanguageInterface::LANGCODE_DEFAULT, '_');
$transliterated = mb_strtolower($transliterated);

$transliterated = preg_replace('@[^a-z0-9_.]+@', '_', $transliterated);

return $transliterated;
}

}
Loading