Skip to content

Instantly share code, notes, and snippets.

@manoj-apare
manoj-apare / .lando.yml
Last active April 7, 2022 13:31
Drupal multisite using Lando
name: website
recipe: drupal9
config:
webroot: docroot
php: 8.0
database: mysql:5.7
xdebug: "debug,coverage"
composer_version: '2'
config:
php: .vscode/php.ini # PHP Xdebug setting https://docs.lando.dev/guides/lando-with-vscode.html#getting-started
<?php
// Get block configuration.
$config = $this->getConfiguration();
// Initiate tag cloud plugin manager.
$tag_cloud_manager = \Drupal::service('plugin.manager.tag_cloud');
// Create instance of user selected tag cloud plugin style and execute build method.
return $tag_cloud_manager
->createInstance($config['style'])
->build($terms);
<?php
// Get all defined plugins of plugin type tag_cloud. Where the definition is simply annotation value.
$tag_cloud_plugin_definitions = \Drupal::service('plugin.manager.tag_cloud')->getDefinitions();
$tag_cloud_styles = [];
// Create form select option array with key as plugin id.
foreach ($tag_cloud_plugin_definitions as $plugin_id => $plugin_definition) {
$tag_cloud_styles[$plugin_id] = $plugin_definition['label']->render();
}
$form['style'] = [
'#type' => 'select',
<?php
namespace Drupal\dynamictagclouds\Plugin\TagCloud;
use Drupal\dynamictagclouds\Plugin\TagCloudBase;
/**
* Default tag cloud style.
*
<?php
namespace Drupal\dynamictagclouds\Plugin;
use Drupal\Component\Plugin\PluginBase;
/**
* Base class for Tag cloud plugins.
*/
abstract class TagCloudBase extends PluginBase implements TagCloudInterface {
<?php
namespace Drupal\dynamictagclouds\Plugin\TagCloud;
use Drupal\dynamictagclouds\Plugin\TagCloudInterface;
/**
* @TagCloud(
* id = "default_tag_cloud",
<?php
namespace Drupal\commerce_shipping\Packer;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\profile\Entity\ProfileInterface;
use Drupal\commerce_shipping\Packer\PackerInterface;
/**
custom_module.custom_packer:
class: Drupal\custom_module\Packer\CustomPacker
arguments: ['@entity_type.manager']
tags:
- { name: commerce_shipping.packer, priority: 0 }
<?php
/**
* {@inheritdoc}
*/
public function pack(OrderInterface $order, ProfileInterface $shipping_profile) {
$proposed_shipments = [];
$packages = [
'vendor_one' => [],
'vendor_two' => [],
];
/**
* {@inheritdoc}
*/
public function applies(OrderInterface $order, ProfileInterface $shipping_profile) {
return $shipping_profile->address->country_code != 'CN';
}