Skip to content

Instantly share code, notes, and snippets.

@jerrac
Created March 13, 2020 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerrac/7b9854329a1eeab4069434bd3389d6a2 to your computer and use it in GitHub Desktop.
Save jerrac/7b9854329a1eeab4069434bd3389d6a2 to your computer and use it in GitHub Desktop.
field_mulitsite_permissions Errors
multisite_drupal | [Fri Mar 13 22:30:59.584102 2020] [php7:notice] [pid 24] [client 172.18.0.1:55790] Error: Cannot create references to/from string offsets in /var/www/html/web/core/lib/Drupal/Component/Utility/NestedArray.php on line 155 #0 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1247): Drupal\\Component\\Utility\\NestedArray::setValue(Array, Array, NULL)\n#1 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(992): Drupal\\Core\\Form\\FormBuilder->handleInputElement('node_multisite_...', Array, Object(Drupal\\Core\\Form\\FormState))\n#2 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1062): Drupal\\Core\\Form\\FormBuilder->doBuildForm('node_multisite_...', Array, Object(Drupal\\Core\\Form\\FormState))\n#3 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1062): Drupal\\Core\\Form\\FormBuilder->doBuildForm('node_multisite_...', Array, Object(Drupal\\Core\\Form\\FormState))\n#4 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1062): Drupal\\Core\\Form\\FormBuilder->doBuildForm('node_multisite_...', Array, Object(Drupal\\Core\\Form\\FormState))\n#5 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1062): Drupal\\Core\\Form\\FormBuilder->doBuildForm('node_multisite_...', Array, Object(Drupal\\Core\\Form\\FormState))\n#6 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1062): Drupal\\Core\\Form\\FormBuilder->doBuildForm('node_multisite_...', Array, Object(Drupal\\Core\\Form\\FormState))\n#7 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(563): Drupal\\Core\\Form\\FormBuilder->doBuildForm('node_multisite_...', Array, Object(Drupal\\Core\\Form\\FormState))\n#8 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(320): Drupal\\Core\\Form\\FormBuilder->processForm('node_multisite_...', Array, Object(Drupal\\Core\\Form\\FormState))\n#9 /var/www/html/web/core/lib/Drupal/Core/Controller/FormController.php(91): Drupal\\Core\\Form\\FormBuilder->buildForm(Object(Drupal\\node\\NodeForm), Object(Drupal\\Core\\Form\\FormState))\n#10 [internal function]: Drupal\\Core\\Controller\\FormController->getContentResult(Object(Symfony\\Component\\HttpFoundation\\Request), Object(Drupal\\Core\\Routing\\RouteMatch))\n#11 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)\n#12 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(573): Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->Drupal\\Core\\EventSubscriber\\{closure}()\n#13 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\\Core\\Render\\Renderer->executeInRenderContext(Object(Drupal\\Core\\Render\\RenderContext), Object(Closure))\n#14 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)\n#15 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->Drupal\\Core\\EventSubscriber\\{closure}()\n#16 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw(Object(Symfony\\Component\\HttpFoundation\\Request), 1)\n#17 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\\Component\\HttpKernel\\HttpKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#18 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\\Core\\StackMiddleware\\Session->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#19 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\\Core\\StackMiddleware\\KernelPreHandle->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#20 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\\page_cache\\StackMiddleware\\PageCache->pass(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#21 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\\page_cache\\StackMiddleware\\PageCache->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#22 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\\Core\\StackMiddleware\\ReverseProxyMiddleware->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#23 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\\Core\\StackMiddleware\\NegotiationMiddleware->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#24 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(694): Stack\\StackedHttpKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#25 /var/www/html/web/index.php(19): Drupal\\Core\\DrupalKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request))\n#26 {main}, referer: http://localhost:9960/node/add/multisite_role
multisite_drupal | 172.18.0.1 - - [13/Mar/2020:22:30:59 +0000] "POST /node/add/multisite_role?ajax_form=1&_wrapper_format=drupal_ajax HTTP/1.1" 200 229 "http://localhost:9960/node/add/multisite_role" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0"
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_multisite_permissions
- field.storage.node.field_multisite_role_member
- node.type.multisite_role
module:
- multisite
id: node.multisite_role.field_multisite_permissions
field_name: field_multisite_permissions
entity_type: node
bundle: multisite_role
label: Multisite Permissions
description: 'A permission that is applied to uses in the role.'
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: multisite_permission_item
</pre>
langcode: en
status: true
dependencies:
module:
- multisite
- node
id: node.field_multisite_permissions
field_name: field_multisite_permissions
entity_type: node
type: multisite_permission_item
settings: { }
module: multisite
locked: false
cardinality: -1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
</pre>
multisite_drupal | [Fri Mar 13 22:32:00.195675 2020] [php7:notice] [pid 30] [client 172.18.0.1:55812] Error: Cannot create references to/from string offsets in /var/www/html/web/core/lib/Drupal/Component/Utility/NestedArray.php on line 155 #0 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1247): Drupal\\Component\\Utility\\NestedArray::setValue(Array, Array, NULL)\n#1 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(992): Drupal\\Core\\Form\\FormBuilder->handleInputElement('node_multisite_...', Array, Object(Drupal\\Core\\Form\\FormState))\n#2 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1062): Drupal\\Core\\Form\\FormBuilder->doBuildForm('node_multisite_...', Array, Object(Drupal\\Core\\Form\\FormState))\n#3 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1062): Drupal\\Core\\Form\\FormBuilder->doBuildForm('node_multisite_...', Array, Object(Drupal\\Core\\Form\\FormState))\n#4 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1062): Drupal\\Core\\Form\\FormBuilder->doBuildForm('node_multisite_...', Array, Object(Drupal\\Core\\Form\\FormState))\n#5 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1062): Drupal\\Core\\Form\\FormBuilder->doBuildForm('node_multisite_...', Array, Object(Drupal\\Core\\Form\\FormState))\n#6 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1062): Drupal\\Core\\Form\\FormBuilder->doBuildForm('node_multisite_...', Array, Object(Drupal\\Core\\Form\\FormState))\n#7 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(563): Drupal\\Core\\Form\\FormBuilder->doBuildForm('node_multisite_...', Array, Object(Drupal\\Core\\Form\\FormState))\n#8 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(320): Drupal\\Core\\Form\\FormBuilder->processForm('node_multisite_...', Array, Object(Drupal\\Core\\Form\\FormState))\n#9 /var/www/html/web/core/lib/Drupal/Core/Controller/FormController.php(91): Drupal\\Core\\Form\\FormBuilder->buildForm(Object(Drupal\\node\\NodeForm), Object(Drupal\\Core\\Form\\FormState))\n#10 [internal function]: Drupal\\Core\\Controller\\FormController->getContentResult(Object(Symfony\\Component\\HttpFoundation\\Request), Object(Drupal\\Core\\Routing\\RouteMatch))\n#11 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)\n#12 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(573): Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->Drupal\\Core\\EventSubscriber\\{closure}()\n#13 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\\Core\\Render\\Renderer->executeInRenderContext(Object(Drupal\\Core\\Render\\RenderContext), Object(Closure))\n#14 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)\n#15 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->Drupal\\Core\\EventSubscriber\\{closure}()\n#16 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw(Object(Symfony\\Component\\HttpFoundation\\Request), 1)\n#17 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\\Component\\HttpKernel\\HttpKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#18 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\\Core\\StackMiddleware\\Session->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#19 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\\Core\\StackMiddleware\\KernelPreHandle->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#20 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\\page_cache\\StackMiddleware\\PageCache->pass(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#21 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\\page_cache\\StackMiddleware\\PageCache->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#22 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\\Core\\StackMiddleware\\ReverseProxyMiddleware->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#23 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\\Core\\StackMiddleware\\NegotiationMiddleware->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#24 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(694): Stack\\StackedHttpKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#25 /var/www/html/web/index.php(19): Drupal\\Core\\DrupalKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request))\n#26 {main}, referer: http://localhost:9960/node/add/multisite_role
multisite_drupal | 172.18.0.1 - - [13/Mar/2020:22:32:00 +0000] "POST /node/add/multisite_role HTTP/1.1" 500 337 "http://localhost:9960/node/add/multisite_role" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0"
<?php
namespace Drupal\multisite\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
use Drupal;
/**
* Plugin implementation of the 'multisite_permission_default' formatter.
*
* @FieldFormatter(
* id = "multisite_permission_default",
* module = "multisite",
* label = @Translation("Set Permission"),
* field_types = {
* "multisite_permission_item"
* }
* )
*/
class MultisitePermissionDefaultFormatter extends FormatterBase {
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
// $elements = [];
// foreach ($items as $delta => $item) {
//// $elements[$delta] = ['#markup' => $item->view() ];
// $elements[$delta] = $item->view();
// }
// return $elements;
return $items->view();
}
}
?>
<?php
namespace Drupal\multisite\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Plugin\migrate\source\d6\Field;
/**
* Plugin implementation of the 'multisite_permission_item' field type.
*
* @FieldType(
* id = "multisite_permission_item",
* label = @Translation("Multisite Permission"),
* description = @Translation("Sets permissions for Multisite Roles on
* Content Types."), category = @Translation("Multisite"), default_widget =
* "multisite_permission_default", default_formatter =
* "multisite_permission_default"
* )
*/
class MultisitePermissionItem extends FieldItemBase {
const VERB_MAXLENGTH = 16;
/**
* {@inheritDoc}
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return [
'columns' => [
'verb' => [
'type' => 'char',
'length' => static::VERB_MAXLENGTH,
'not null' => TRUE,
],
'content_type' => [
'type' => 'char',
'length' => 255,
'not null' => TRUE,
],
],
'indexes' => [
'verb' => ['verb'],
'content_type' => ['content_type'],
],
];
}
/**
* {@inheritDoc}
*/
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['verb'] = DataDefinition::create('string')
->setLabel(t('Verb'));
$properties['content_type'] = DataDefinition::create('string')
->setLabel(t('Content Type'));
return $properties;
}
/**
* {@inheritDoc}
*/
public function isEmpty() {
$value = $this->get('verb')->getValue();
return $value === NULL || $value === '';
}
/**
* {@inheritdoc}
*/
public function getConstraints() {
$constraint_manager = \Drupal::typedDataManager()
->getValidationConstraintManager();
$constraints = parent::getConstraints();
$constraints[] = $constraint_manager->create('ComplexData', [
'verb' => [
'Length' => [
'max' => static::VERB_MAXLENGTH,
'maxMessage' => t('%name: the permission verb may not be longer than @max characters.', [
'%name' => $this->getFieldDefinition()
->getLabel(),
'@max' => static::VERB_MAXLENGTH,
]),
],
],
]);
return $constraints;
}
}
?>
<?php
namespace Drupal\multisite\Plugin\Field\FieldWidget;
use Drupal;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Plugin implementation of the 'multisite_permission_default' widget.
*
* @FieldWidget(
* id = "multisite_permission_default",
* label = @Translation("Set Permission"),
* field_types = {
* "multisite_permission_item"
* }
* )
*/
class MultisitePermissionDefaultWidget extends WidgetBase {
/**
* {@inheritDoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$verbs = [
0=>"view any",
1=>"view own",
2=>"view revisions",
3=>"create new",
4=>"edit any",
5=>"edit own",
6=>"revert revisions",
7=>"delete revisions",
8=>"delete any",
9=>"delete own",
];
$element['value'] = $element + [
'#type' => 'select',
'#options' => $verbs,
'#empty_value' => '',
//'#default_value' => (isset($items[$delta]->value) && isset($verbs[$items[$delta]->value])) ? $items[$delta]->value : NULL,
'#description' => t('Select a verb'),
];
// Get list of bundles that use field_multisite_ref.
$content_type_options = [];
$entityFieldManager = \Drupal::service("entity_field.manager");
$fieldMapByFieldType = $entityFieldManager->getFieldMapByFieldType("entity_reference");
if(isset($fieldMapByFieldType["node"]["field_multisite_ref"]) && isset($fieldMapByFieldType["node"]["field_multisite_ref"]["bundles"])){
$bundles = $fieldMapByFieldType["node"]["field_multisite_ref"]["bundles"];
$count = 0;
foreach($bundles as $key => $val){
$content_type_options[$count]=$val;
$count++;
}
}
$element['content_type'] = $element + [
'#type' => 'select',
'#options' => $content_type_options,
'#empty_value' => '',
'#description' => t('Select a content type. The type must use the field_multisite_ref field for it to be listed here.'),
];
return $element;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment