Skip to content

Instantly share code, notes, and snippets.

<?php
namespace Drupal\gojara_activity_results\Plugin\views\field;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
@init90
init90 / gojara_global.module
Created April 19, 2022 15:50
Sort comments by rating and leave default sorting for threads.
/**
* Implements hook_query_TAG_alter() for comments.
*
* @see CommentStorage::loadThread().
*/
function gojara_global_query_comment_filter_alter(AlterableInterface $query) {
// Sort comments by rating and leave default sorting for threads.
if ($query->getMetaData('field_name') === 'comment') {
$order_by = &$query->getOrderBy();
$expression = &$query->getExpressions();
@init90
init90 / commerce-order-receipt.html.twig
Created January 18, 2021 11:44
Drupal 8, show attributes from order item.
{% for attribute_data in order_item.getPurchasedEntity().getAttributeValues() %}
<tr>
<td align="left" valign="top" class="product-attr" style="color: #000000; font-family: 'Nunito Sans', sans-serif; font-weight: 400; font-size: 14px; line-height: 22px;">{{ attribute_data.getAttribute().label() }}: {{ attribute_data.label() }}</td>
</tr>
{% endfor %}
@init90
init90 / ProductType.php
Created September 20, 2020 08:43
Product type block visibility condition plugin.
<?php
namespace Drupal\swimsports_commerce\Plugin\Condition;
use Drupal\Core\Condition\ConditionPluginBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@init90
init90 / *.module
Created September 20, 2020 08:26
Hide price field for specific view mode.
/**
* Implements hook_ENTITY_TYPE_view_alter() for 'commerce_product' entities.
*/
function swimsports_commerce_commerce_product_view_alter(array &$build, EntityInterface $node, EntityViewDisplayInterface $display) {
// Hide price field. For some reason we cannot configure price visibility
// from UI.
if ($build['#view_mode'] === 'add_to_cart_confirmation_view') {
$build['variation_price']['#access'] = FALSE;
}
}
@init90
init90 / *.module
Created September 20, 2020 08:12
Render view programatically with redoved text block from view header
$view = Views::getView('related_products');
$view->setDisplay('default');
$view->removeHandler('default', 'header', 'area');
$view_render_info = $view->render();
$build['related_products_carusel'] = [
'#markup' => \Drupal::service('renderer')->render($view_render_info),
];
@init90
init90 / gist:e02589cc7b9d983db00e79596f92ed40
Created December 9, 2019 20:53
Install Docksal on Ubuntu 19.10
Ubuntu 19.10 don't have official Docker support so should add it manually:
Add docker repository:
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
disco \
stable"
Update packages:
sudo apt-get update
@init90
init90 / pw_submission.module
Created December 5, 2019 10:54
Drupal 8, get commented entity from comment form.
$comment = $form_state->getFormObject()->getEntity();
$submission = $comment->getCommentedEntity();
@init90
init90 / pw_submission.module
Created December 5, 2019 08:10
Get group from views contextual filter argument.
$group = NULL;
foreach ($view->argument as $arg) {
if ($arg->getPluginId() !== 'group_id') {
continue;
}
$group = Group::load($arg->getValue());
break;
}
@init90
init90 / gm_search_domain_filter.module
Created July 1, 2019 08:43
Drupal 7, create Search API query programatically.
$index = search_api_index_load('index_name');
$query = new SearchApiQuery($index);
$query->condition('type', 'blog', '=');
$results = $query->execute();