Skip to content

Instantly share code, notes, and snippets.

View levmyshkin's full-sized avatar

Ivan Abramenko levmyshkin

View GitHub Profile
body {
backround: #2B2B2B !important;
}
#page {
background: #2B2B2B;
}
body {
color: #A9B7C6;
@levmyshkin
levmyshkin / gist:c3d8855084f91cb45fae33253e10e765
Created November 19, 2021 06:34
Install Drupal with composer
composer create-project drupal/recommended-project site_folder
drush site:install
@levmyshkin
levmyshkin / script.js
Created November 19, 2021 06:42
Drupal javascript behavior execute code once for element
(function ($, Drupal, once) {
Drupal.behaviors.myModuleBehavior = {
attach: function (context, settings) {
once('myCustomBehavior', 'input.myCustomBehavior', context).forEach(function () {
// Apply the myCustomBehaviour effect to the elements only once.
});
}
};
})(jQuery, Drupal, once);
@levmyshkin
levmyshkin / THEME.libraries.yml
Last active November 19, 2021 13:16
Drupal behavior run script once
foobar:
js:
js/foobar.js: {}
dependencies:
- core/drupal
- core/jquery
- core/once
@levmyshkin
levmyshkin / THEME.libraries.yml
Last active November 19, 2021 13:16
Drupal javascript behavior example
foobar:
js:
js/foobar.js: {}
dependencies:
- core/drupal
- core/jquery
- core/once
@levmyshkin
levmyshkin / FirstPageController.php
Last active November 19, 2021 13:35
Create a custom Drupal module with route and controller
<?php
/**
* @file /modules/custom/drupalbook/src/Controller/FirstPageController.php
*/
namespace Drupal\drupalbook\Controller;
/**
* Provides route responses for the DrupalBook module.
@levmyshkin
levmyshkin / FirstPageController.php
Last active November 19, 2021 13:35
Drupal: Creating pages for a premium account programmatically
<?php
/**
* @file /modules/custom/drupalbook/src/Controller/FirstPageController.php
*/
namespace Drupal\drupalbook\Controller;
/**
* Provides route responses for the DrupalBook module.
@levmyshkin
levmyshkin / DisplayNode.php
Created November 19, 2021 13:42
Drupal Route with parameter
<?php
//modules/custom/drupalbook/src/Controller/DisplayNode.php
namespace Drupal\drupalbook\Controller;
use Drupal\Core\Access\AccessResult;
use Drupal\node\NodeInterface;
/**
* Provides route responses for the DrupalBook module.
@levmyshkin
levmyshkin / DrupalbookSettingsForm.php
Created November 19, 2021 13:45
Add Drupal configuration form programmatically
<?php
// /modules/custom/drupalbook/src/Form/DrupalbookSettingsForm.php
namespace Drupal\drupalbook\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Configure example settings for this site.
*/
@levmyshkin
levmyshkin / drupalbook.module
Created November 19, 2021 13:47
Drupal hook_form_alter() add submit and validate for existing form
<?php
/**
* Implements hook_form_alter().
*/
function drupalbook_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
if ($form_id == 'drupalbook_admin_settings') {
$form['drupalbook_api_key']['#attributes']['placeholder'] = 'API key';
$form['drupalbook_api_client_id']['#attributes']['placeholder'] = 'API client ID';