getThirdPartySetting example

/** * Returns the synchronization settings for the specified field. * * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition * A field definition. * * @return string[] * An array of synchronized field property names. */
  protected function getFieldSynchronizationSettings(FieldDefinitionInterface $field_definition) {
    if ($field_definition instanceof ThirdPartySettingsInterface && $field_definition->isTranslatable()) {
      return $field_definition->getThirdPartySetting('content_translation', 'translation_sync', []);
    }
    return [];
  }

  /** * {@inheritdoc} */
  public function synchronizeFields(ContentEntityInterface $entity$sync_langcode$original_langcode = NULL) {
    $translations = $entity->getTranslationLanguages();

    // If we have no information about what to sync to, if we are creating a new

function hook_field_formatter_third_party_settings_form(\Drupal\Core\Field\FormatterInterface $plugin, \Drupal\Core\Field\FieldDefinitionInterface $field_definition$view_mode, array $form, \Drupal\Core\Form\FormStateInterface $form_state) {
  $element = [];
  // Add a 'my_setting' checkbox to the settings form for 'foo_formatter' field   // formatters.   if ($plugin->getPluginId() == 'foo_formatter') {
    $element['my_setting'] = [
      '#type' => 'checkbox',
      '#title' => t('My setting'),
      '#default_value' => $plugin->getThirdPartySetting('my_module', 'my_setting'),
    ];
  }
  return $element;
}

/** * Allow modules to add settings to field widgets provided by other modules. * * @param \Drupal\Core\Field\WidgetInterface $plugin * The instantiated field widget plugin. * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition * The field definition. * @param string $form_mode * The entity form mode. * @param array $form * The (entire) configuration form array. * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state. * * @return array * Returns the form array to be built. * * @see \Drupal\field_ui\Form\EntityFormDisplayEditForm::thirdPartySettingsForm() */
'plugin' => 'action_message_action',
    ]);
    $entity->save();

    $this->assertSame([]$entity->getThirdPartyProviders());
    // Get a copy of the configuration before the third party setting is added.     $no_third_part_setting_config = $this->container->get('config.storage')->read($name);

    // Add a third party setting.     $entity->setThirdPartySetting('config_test', 'integer', 1);
    $entity->save();
    $this->assertSame(1, $entity->getThirdPartySetting('config_test', 'integer'));
    $has_third_part_setting_config = $this->container->get('config.storage')->read($name);

    // Ensure configuration imports can completely remove third party settings.     $this->assertConfigUpdateImport($name$has_third_part_setting_config$no_third_part_setting_config);
  }

  /** * Tests that a single set of plugin config stays in sync. * * @param \Drupal\Core\Entity\EntityWithPluginCollectionInterface $entity * The entity. * @param string $config_key * Where the plugin config is stored. * @param string $setting_key * The setting within the plugin config to change. * @param mixed $expected * The expected default value of the plugin config setting. */
$this->assertSame($display_submitted$entity->displaySubmitted(), 'Submission info is displayed');
    $this->assertSame($new_revision$entity->shouldCreateNewRevision(), 'Is a new revision');

    if ($body_label) {
      /** @var \Drupal\field\FieldConfigInterface $body */
      $body = FieldConfig::load('node.' . $id . '.body');
      $this->assertInstanceOf(FieldConfigInterface::class$body);
      $this->assertSame($body_label$body->label());
    }

    $this->assertSame($expected_available_menus$entity->getThirdPartySetting('menu_ui', 'available_menus'));
    $this->assertSame($expected_parent$entity->getThirdPartySetting('menu_ui', 'parent'));
  }

  /** * Tests Drupal 7 node type to Drupal 8 migration. */
  public function testNodeType() {
    $expected_available_menus = ['main-menu'];
    $expected_parent = 'main-menu:0:';

    $this->assertEntity('article', 'Article', 'Use <em>articles</em> for time-sensitive content like news, press releases or blog posts.', 'Help text for articles', TRUE, FALSE, $expected_available_menus$expected_parent, "Body");
    
$this->assertTrue($node_type_page->displaySubmitted());
    $this->assertFalse($node_type_page->shouldCreateNewRevision());
    $this->assertSame(DRUPAL_OPTIONAL, $node_type_page->getPreviewMode());
    $this->assertSame($id_map->lookupDestinationIds(['test_page'])[['test_page']]);

    // Test we have a body field.     $field = FieldConfig::loadByName('node', 'test_page', 'body');
    $this->assertSame('This is the body field label', $field->getLabel(), 'Body field was found.');

    // Test default menus.     $expected_available_menus = ['navigation'];
    $this->assertSame($expected_available_menus$node_type_page->getThirdPartySetting('menu_ui', 'available_menus'));
    $expected_parent = 'navigation:';
    $this->assertSame($expected_parent$node_type_page->getThirdPartySetting('menu_ui', 'parent'));

    // Test the test_story content type.     $node_type_story = NodeType::load('test_story');
    $this->assertSame('test_story', $node_type_story->id(), 'Node type test_story loaded');

    $this->assertTrue($node_type_story->displaySubmitted());
    $this->assertFalse($node_type_story->shouldCreateNewRevision());
    $this->assertSame(DRUPAL_OPTIONAL, $node_type_story->getPreviewMode());
    $this->assertSame([['test_story']]$id_map->lookupDestinationIds(['test_story']));

    
$this->drupalLogout();
    $this->drupalGet('contact');
    $this->assertSession()->pageTextContains('Your email address');
    $this->assertSession()->pageTextNotContains('Form');
    $this->submitContact($name = $this->randomMachineName(16)$mail$subject = $this->randomMachineName(16)$id$message = $this->randomMachineName(64));
    $this->assertSession()->pageTextContains('Your message has been sent.');

    $messages = Message::loadMultiple();
    /** @var \Drupal\contact\Entity\Message $message */
    $message = reset($messages);
    $this->assertEquals($id$message->getContactForm()->id());
    $this->assertTrue($message->getContactForm()->getThirdPartySetting('contact_storage_test', 'send_a_pony', FALSE));
    $this->assertEquals($name$message->getSenderName());
    $this->assertEquals($subject$message->getSubject());
    $this->assertEquals($mail$message->getSenderMail());

    $config = $this->config("contact.form.$id");
    $this->assertEquals($id$config->get('id'));
  }

}
$page->findButton('Update')->click();
    $assert_session->assertWaitOnAjaxRequest();
    $button_save->click();

    // Assert the third party settings.     \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
    $this->drupalGet($manage_display);

    $id = 'node.' . $this->type . '.default';
    /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
    $display = $displayStorage->loadUnchanged($id);
    $this->assertEquals('foo', $display->getRenderer('field_test')->getThirdPartySetting('field_third_party_test', 'field_test_field_formatter_third_party_settings_form'));
    $this->assertContains('field_third_party_test', $display->calculateDependencies()->getDependencies()['module'], 'The display has a dependency on field_third_party_test module.');

    // Change the formatter to an empty setting and validate it's initialized     // correctly.     $field_test_format_type = $page->findField('fields[field_test][type]');
    $field_test_format_type->setValue('field_empty_setting');
    $assert_session->assertWaitOnAjaxRequest();
    $assert_session->responseNotContains('Default empty setting now has a value.');
    $this->assertTrue($field_test_settings->isVisible(), TRUE);

    // Set the empty_setting option to a non-empty value again and validate
/** * {@inheritdoc} */
  public function setThirdPartySetting($module$key$value) {
    return $this->storage->setThirdPartySetting($module$key$value);
  }

  /** * {@inheritdoc} */
  public function getThirdPartySetting($module$key$default = NULL) {
    return $this->storage->getThirdPartySetting($module$key$default);
  }

  /** * {@inheritdoc} */
  public function getThirdPartySettings($module) {
    return $this->storage->getThirdPartySettings($module);
  }

  /** * {@inheritdoc} */
/** * {@inheritdoc} */
  protected function createEntity() {
    /** @var \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay $entity */
    $entity = parent::createEntity();
    $entity
      ->enableLayoutBuilder()
      ->setOverridable()
      ->save();
    $this->assertCount(1, $entity->getThirdPartySetting('layout_builder', 'sections'));
    return $entity;
  }

  /** * {@inheritdoc} */
  protected function getExpectedDocument() {
    $document = parent::getExpectedDocument();
    array_unshift($document['data']['attributes']['dependencies']['module'], 'layout_builder');
    $document['data']['attributes']['hidden'][OverridesSectionStorage::FIELD_NAME] = TRUE;
    $document['data']['attributes']['third_party_settings']['layout_builder'] = [
      

  public function testThirdPartySettings() {
    $key = 'test';
    $third_party = 'test_provider';
    $value = $this->getRandomGenerator()->string();

    // Test getThirdPartySetting() with no settings.     $this->assertEquals($value$this->entity->getThirdPartySetting($third_party$key$value));
    $this->assertNull($this->entity->getThirdPartySetting($third_party$key));

    // Test setThirdPartySetting().     $this->entity->setThirdPartySetting($third_party$key$value);
    $this->assertEquals($value$this->entity->getThirdPartySetting($third_party$key));
    $this->assertEquals($value$this->entity->getThirdPartySetting($third_party$key$this->getRandomGenerator()->string()));

    // Test getThirdPartySettings().     $this->entity->setThirdPartySetting($third_party, 'test2', 'value2');
    $this->assertEquals([$key => $value, 'test2' => 'value2']$this->entity->getThirdPartySettings($third_party));

    
// Set $entityFieldManager before calling the parent constructor because the     // constructor will call init() which then calls setComponent() which needs     // $entityFieldManager.     $this->entityFieldManager = \Drupal::service('entity_field.manager');
    parent::__construct($values$entity_type);
  }

  /** * {@inheritdoc} */
  public function isOverridable() {
    return $this->isLayoutBuilderEnabled() && $this->getThirdPartySetting('layout_builder', 'allow_custom', FALSE);
  }

  /** * {@inheritdoc} */
  public function setOverridable($overridable = TRUE) {
    $this->setThirdPartySetting('layout_builder', 'allow_custom', $overridable);
    // Enable Layout Builder if it's not already enabled and overriding.     if ($overridable && !$this->isLayoutBuilderEnabled()) {
      $this->enableLayoutBuilder();
    }
    

  public function disableLayoutBuilder() {
    $this->getDisplay()->disableLayoutBuilder();
    return $this;
  }

  /** * {@inheritdoc} */
  public function getThirdPartySetting($module$key$default = NULL) {
    return $this->getDisplay()->getThirdPartySetting($module$key$default);
  }

  /** * {@inheritdoc} */
  public function getThirdPartySettings($module) {
    return $this->getDisplay()->getThirdPartySettings($module);
  }

  /** * {@inheritdoc} */

  protected function getLayoutDefinition($layout_id) {
    return \Drupal::service('plugin.manager.core.layout')->getDefinition($layout_id);
  }

  /** * Implements \Drupal\field_layout\Display\EntityDisplayWithLayoutInterface::getLayoutId(). */
  public function getLayoutId() {
    return $this->getThirdPartySetting('field_layout', 'id');
  }

  /** * Implements \Drupal\field_layout\Display\EntityDisplayWithLayoutInterface::getLayoutSettings(). */
  public function getLayoutSettings() {
    return $this->getThirdPartySetting('field_layout', 'settings', []);
  }

  /** * Implements \Drupal\field_layout\Display\EntityDisplayWithLayoutInterface::setLayoutId(). */
// Check that the display can be properly saved and read back.     $display->save();
    $display = EntityViewDisplay::load($display->id());
    foreach (['component_1', 'component_2', 'component_3'] as $name) {
      $expected[$name]['region'] = 'content';
      $this->assertEquals($expected[$name]$display->getComponent($name));
    }

    // Ensure that third party settings were added to the config entity.     // These are added by entity_test_entity_presave() implemented in     // entity_test module.     $this->assertEquals('bar', $display->getThirdPartySetting('entity_test', 'foo'), 'Third party settings were added to the entity view display.');

    // Check that getComponents() returns options for all components.     $expected['name'] = [
      'label' => 'hidden',
      'type' => 'string',
      'weight' => -5,
      'settings' => [
        'link_to_entity' => FALSE,
      ],
      'third_party_settings' => [],
      'region' => 'content',
    ];
$this->assertSession()->pageTextContains("Add {$effect_label} effect to style {$style_label}");
        $this->submitForm($edit_data, 'Add effect');
      }
    }

    // Load the saved image style.     $style = ImageStyle::load($style_name);

    // Ensure that third party settings were added to the config entity.     // These are added by a hook_image_style_presave() implemented in     // image_module_test module.     $this->assertEquals('bar', $style->getThirdPartySetting('image_module_test', 'foo'), 'Third party settings were added to the image style.');

    // Ensure that the image style URI matches our expected path.     $style_uri_path = $style->toUrl()->toString();
    $this->assertStringContainsString($style_path$style_uri_path, 'The image style URI is correct.');

    // Confirm that all effects on the image style have settings that match     // what was saved.     $uuids = [];
    foreach ($style->getEffects() as $uuid => $effect) {
      // Store the uuid for later use.       $uuids[$effect->getPluginId()] = $uuid;
      
Home | Imprint | This part of the site doesn't use cookies.