Skip to content

Instantly share code, notes, and snippets.

View kedramon's full-sized avatar
🇺🇦
stand with Ukraine

kedramon kedramon

🇺🇦
stand with Ukraine
View GitHub Profile
@kedramon
kedramon / Drupal-mismatched-entity-and-or-field-definitions.md
Created January 26, 2022 15:20
[Drupal] How to solve "Mismatched entity and/or field definitions"

If you see in the Status Report error section with fields marked as mismatched this is what you can try to do.

drush entup command was removed starting from some version, so thes method is not relevant anymore.

Given Drupal Core 9.3.3, I attempted the following process which finally resolved the errors without the drush command.

Spot where from comes the field itself, could be Paragraph, Block, Node, or other Entity.

From the administrative menu, navigate to Manage Fields and edit the field, open tab Field settings and simply click "Save".

###Problem File contained CRLF line endings, they was replaced with LF but now file is marked as changed: git status

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   assets/social/twitter.svg
@kedramon
kedramon / datetime_custom.php
Created May 19, 2020 08:30
Date field rendered as custom date field using view options array.
<?php
$options = [
'label' => 'inline',
'settings' => ['date_format' => 'd.m.Y'],
'type' => 'datetime_custom',
];
$date = $entity->get('field_date')->view($options);
$entities = $entity->get('field_NAME')->referencedEntities();
@kedramon
kedramon / PinPukController.php
Last active December 23, 2020 22:55
[Drupal8] Bootstrap + Ajax button = fill content, one call.
<?php
namespace Drupal\order\Controller;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\InvokeCommand;
use Drupal\Core\Ajax\ReplaceCommand;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
@kedramon
kedramon / snippet.php
Created July 20, 2017 14:39
Redirect user after register form submit to internal page.
/**
* Implements hook_form_BASE_FORM_ID_alter().
*/
function ns_user_form_user_register_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$form['actions']['submit']['#value'] = t('Send');
$form['#attached']['library'][] = 'core/jquery.ui.tooltip';
$form['#attached']['library'][] = 'nedapsecurity/tooltips';
$form['actions']['submit']['#submit'][] = 'ns_user_register_submit_handler';
}
@kedramon
kedramon / article.md
Last active July 26, 2016 09:33
Entity reference - customizability at its best

This article is a copy of http://kybest.hu/en/blog/entity-reference-customizability-at-its-best from google cache. I found it usefull

#Entity reference - customizability at its best

Submitted by CZÖVEK András on 2013-11-26, Tuesday, 17:29 The Entity reference module is one of the most used Drupal modules. At the moment of writing it is 51st on the usage list of Drupal projects. Those who have already made a Drupal site probably have knows it. At the same time, not many know what a powerful tool it can be even in special cases.

The quality of a Drupal module is quite well characterized by its customizability. If a module produces markup for instance we expect to be able to alter that markup through the theme layer of Drupal. The Entity reference is an excellently written module in this aspect (too). But what should be customized in the Entity reference module?

In one of the sites recently produced by us one part of the content comes from an external source. These contents are digitalized books stored on t

@kedramon
kedramon / autocomplete.custom.js
Created June 16, 2015 09:32
Handler for the "onkeydown" event to submit the autocomplete input by hitting the Enter key, also input must have a 'auto-submit' class
(function ($) {
Drupal.jsAC.prototype.onkeydown = function (input, e) {
if (!e) {
e = window.event;
}
switch (e.keyCode) {
case 13: // Enter.
if ($(input).hasClass('auto-submit')) {
this.hidePopup(e.keyCode);
input.form.submit();
@kedramon
kedramon / duplicate_aliases.php
Created March 13, 2014 09:27
Get list of url aliases which ends with -0 -1 -2 or -3 #drupal7
<?php
$items = array();
$query = db_select('node', 'n');
$query->join('url_alias', 'ua', "ua.source = CONCAT('node/', n.nid)");
$query->fields('ua', array('source'))
->fields('n', array('title'))
->condition(
db_or()
->condition('ua.alias', '%' . db_like('-0'), 'LIKE')
->condition('ua.alias', '%' . db_like('-1'), 'LIKE')
@kedramon
kedramon / drupal7_apple-touch-icon.php
Created December 19, 2013 13:42
Drupal 7. Add apple-touch-icon.png in your theme folder I use 120x120 image size
<?php
function YOUR_THEME_NAME_preprocess_html(&$vars) {
$apple = array(
'#tag' => 'link',
'#attributes' => array(
'href' => base_path() . path_to_theme() .'/apple-touch-icon.png',
'rel' => 'apple-touch-icon',
'sizes' => '120x120'
),
);