Skip to content

Instantly share code, notes, and snippets.

View xuxucode's full-sized avatar

xuxucode xuxucode

  • fulltech co. ltd.
View GitHub Profile
@xuxucode
xuxucode / apparmor-docker-default.js
Last active February 21, 2024 14:06
Get latest `docker-default` AppArmor profile by parsing template.go
// Usage: node apparmor-docker-default.js
const path = require("node:path");
const fs = require("node:fs");
const profileDirectory = "/etc/apparmor.d"
/**
* @typedef ProfileData
* @property {string} name
@xuxucode
xuxucode / import-corejs-missing-modules.md
Last active August 26, 2023 06:43
微信小程序导入缺失的 `core-js` 模块
'use strict';
const mysql = require('mysql2/promise');
// CREATE TABLE `example` (
// `id` int unsigned NOT NULL AUTO_INCREMENT,
// `title` varchar(1024) NOT NULL DEFAULT '',
// `created_at` bigint NOT NULL,
// PRIMARY KEY (`id`)
// ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4;
'use strict';
const mysql = require('mysql2/promise');
// CREATE TABLE `example` (
// `id` int unsigned NOT NULL AUTO_INCREMENT,
// `title` varchar(1024) NOT NULL DEFAULT '',
// `created_at` bigint NOT NULL,
// PRIMARY KEY (`id`)
// ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4;
diff --git a/src/Entity/CommerceContentEntityBase.php b/src/Entity/CommerceContentEntityBase.php
index 026a79c4f..3e62a878e 100644
--- a/src/Entity/CommerceContentEntityBase.php
+++ b/src/Entity/CommerceContentEntityBase.php
@@ -23,7 +23,7 @@ public function getTranslatedReferencedEntities($field_name) {
*/
public function getTranslatedReferencedEntity($field_name) {
$referenced_entities = $this->getTranslatedReferencedEntities($field_name);
- return reset($referenced_entities);
+ return reset($referenced_entities) ?: NULL;
@xuxucode
xuxucode / graphql_query_sort.patch
Last active February 8, 2018 03:32
Sort Drupal GraphQL entity query result
diff --git a/modules/graphql_core/src/Plugin/GraphQL/Fields/EntityQuery/EntityQuery.php b/modules/graphql_core/src/Plugin/GraphQL/Fields/EntityQuery/EntityQuery.php
index 1479897..5e35b82 100644
--- a/modules/graphql_core/src/Plugin/GraphQL/Fields/EntityQuery/EntityQuery.php
+++ b/modules/graphql_core/src/Plugin/GraphQL/Fields/EntityQuery/EntityQuery.php
@@ -27,7 +27,8 @@ use Youshido\GraphQL\Execution\ResolveInfo;
* "limit" = {
* "type" = "Int",
* "default" = 10
- * }
+ * },
diff --git a/modules/payment/src/Controller/PaymentCheckoutController.php b/modules/payment/src/Controller/PaymentCheckoutController.php
index a60605d..2a9e246 100644
--- a/modules/payment/src/Controller/PaymentCheckoutController.php
+++ b/modules/payment/src/Controller/PaymentCheckoutController.php
@@ -2,12 +2,14 @@
namespace Drupal\commerce_payment\Controller;
+use Drupal\commerce\Response\NeedsRedirectException;
use Drupal\commerce_checkout\CheckoutOrderManagerInterface;
@xuxucode
xuxucode / ignore_map_fields.patch
Last active January 25, 2018 01:42
Drupal GraphQL 3.x patch
diff --git a/modules/graphql_core/src/Plugin/Deriver/Fields/EntityFieldDeriver.php b/modules/graphql_core/src/Plugin/Deriver/Fields/EntityFieldDeriver.php
index def5716..ea5e931 100644
--- a/modules/graphql_core/src/Plugin/Deriver/Fields/EntityFieldDeriver.php
+++ b/modules/graphql_core/src/Plugin/Deriver/Fields/EntityFieldDeriver.php
@@ -29,6 +29,10 @@ class EntityFieldDeriver extends EntityFieldDeriverWithTypeMapping {
return [];
}
+ if ($fieldDefinition->getType() === 'map') {
+ return [];
@xuxucode
xuxucode / entity_id_integer_and_index.patch
Last active January 18, 2018 08:40
Drupal entity_id integer and flag_id__uid index
diff --git a/flag.install b/flag.install
index ec4794b..42ba3ba 100644
--- a/flag.install
+++ b/flag.install
@@ -30,9 +30,10 @@ function flag_schema() {
],
'entity_id' => [
'description' => 'The unique ID of the flagged entity, for example the uid, cid, or nid.',
- 'type' => 'varchar_ascii',
- 'length' => ConfigEntityStorage::MAX_ID_LENGTH,