setThirdPartySetting example

$context = $this->prophesize(ContextInterface::class);
    $context->getContextValue()->willReturn($section_list->reveal());
    $this->plugin->setContext('display', $context->reveal());

    $section_list->getThirdPartySetting('the_module', 'the_key', NULL)->willReturn('value 1');

    // The plugin returns the initial value.     $this->assertSame('value 1', $this->plugin->getThirdPartySetting('the_module', 'the_key'));

    // When the section list is updated, also update the result returned.     $section_list->setThirdPartySetting('the_module', 'the_key', 'value 2')->shouldBeCalled()->will(function Darray $args) use ($section_list) {
      $section_list->getThirdPartySetting('the_module', 'the_key', NULL)->willReturn($args[2]);
    });

    // Update the plugin value.     $this->plugin->setThirdPartySetting('the_module', 'the_key', 'value 2');
    // Assert that the returned value matches.     $this->assertSame('value 2', $this->plugin->getThirdPartySetting('the_module', 'the_key'));
  }

  /** * @covers ::extractEntityFromRoute * * @dataProvider providerTestExtractEntityFromRoute * * @param bool $success * Whether a successful result is expected. * @param string|null $expected_entity_id * The expected entity ID. * @param string $value * The value to pass to ::extractEntityFromRoute(). * @param array $defaults * The defaults to pass to ::extractEntityFromRoute(). */

  public function setOverridable($overridable = TRUE) {
    $this->getDisplay()->setOverridable($overridable);
    return $this;
  }

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

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

  /** * {@inheritdoc} */
/** * {@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();
    }
    return $this;
  }

  /** * {@inheritdoc} */
  public function isLayoutBuilderEnabled() {
    
'default value',
      'default value',
    ];
    return $data;
  }

  /** * @covers ::setThirdPartySetting * @dataProvider providerTestSetThirdPartySetting */
  public function testSetThirdPartySetting($provider$key$value$expected) {
    $this->section->setThirdPartySetting($provider$key$value);
    $this->assertSame($expected$this->section->getThirdPartySettings($provider));
  }

  /** * Provides test data for ::testSetThirdPartySettings(). */
  public function providerTestSetThirdPartySetting() {
    $data = [];
    $data[] = [
      'bad_judgement',
      'blink_speed',
      

    ];
  }

  /** * @covers ::calculateDependencies * @covers ::getDependencies * @covers ::onDependencyRemoval */
  public function testCalculateDependenciesWithThirdPartySettings() {
    $this->entity = $this->getMockForAbstractClass('\Drupal\Core\Config\Entity\ConfigEntityBase', [[]$this->entityTypeId]);
    $this->entity->setThirdPartySetting('test_provider', 'test', 'test');
    $this->entity->setThirdPartySetting('test_provider2', 'test', 'test');
    $this->entity->setThirdPartySetting($this->provider, 'test', 'test');

    $this->assertEquals(['test_provider', 'test_provider2']$this->entity->calculateDependencies()->getDependencies()['module']);
    $changed = $this->entity->onDependencyRemoval(['module' => ['test_provider2']]);
    $this->assertTrue($changed, 'Calling onDependencyRemoval with an existing third party dependency provider returns TRUE.');
    $changed = $this->entity->onDependencyRemoval(['module' => ['test_provider3']]);
    $this->assertFalse($changed, 'Calling onDependencyRemoval with a non-existing third party dependency provider returns FALSE.');
    $this->assertEquals(['test_provider']$this->entity->calculateDependencies()->getDependencies()['module']);
  }

  

class PluginSettingsBaseTest extends UnitTestCase {

  /** * @covers ::getThirdPartySettings */
  public function testGetThirdPartySettings() {
    $plugin_settings = new TestPluginSettingsBase();
    $this->assertSame([]$plugin_settings->getThirdPartySettings());
    $this->assertSame([]$plugin_settings->getThirdPartySettings('test'));
    $plugin_settings->setThirdPartySetting('test', 'foo', 'bar');
    $this->assertSame(['foo' => 'bar']$plugin_settings->getThirdPartySettings('test'));
    $this->assertSame([]$plugin_settings->getThirdPartySettings('test2'));
  }

}

class TestPluginSettingsBase extends PluginSettingsBase {

  public function __construct() {
  }

}
'bundle' => $entity_type_id,
      'label' => 'Synchronized field',
      'translatable' => 1,
    ]);
    $field_config->save();

    $property_settings = [
      'alt' => 'alt',
      'title' => 'title',
      'file' => 0,
    ];
    $field_config->setThirdPartySetting('content_translation', 'translation_sync', $property_settings);
    $field_config->save();

    $this->contentTranslationManager = $this->container->get('content_translation.manager');
    $this->contentTranslationManager->setEnabled($entity_type_id$entity_type_id, TRUE);

    $this->storage = $this->entityTypeManager->getStorage($entity_type_id);

    foreach ($this->getTestFiles('image') as $file) {
      $entity = File::create((array) $file + ['status' => 1]);
      $entity->save();
    }

    
/** * Tests the Uninstall page and Uninstall confirmation page. */
  public function testUninstallPage() {
    $account = $this->drupalCreateUser(['administer modules']);
    $this->drupalLogin($account);

    // Create a node type.     $node_type = NodeType::create(['type' => 'uninstall_blocker', 'name' => 'Uninstall blocker']);
    // Create a dependency that can be fixed.     $node_type->setThirdPartySetting('module_test', 'key', 'value');
    $node_type->save();
    // Add a node to prevent node from being uninstalled.     $node = Node::create([
      'type' => 'uninstall_blocker',
      'title' => $this->randomString(),
    ]);
    $node->save();

    // Change the config directly to "install" non-stable modules.     $this->config('core.extension')
      ->set('module.system_status_obsolete_test', 0)
      
      // https://www.drupal.org/node/2796877.       $layout_definition = $this->getLayoutDefinition($layout_id);
      $new_region = $layout_definition->getDefaultRegion();
      $layout_regions = $layout_definition->getRegions();
      foreach ($this->getComponents() as $name => $component) {
        if (isset($component['region']) && !isset($layout_regions[$component['region']])) {
          $component['region'] = $new_region;
          $this->setComponent($name$component);
        }
      }
    }
    $this->setThirdPartySetting('field_layout', 'id', $layout_id);
    // Instantiate the plugin and consult it for the updated plugin     // configuration. Once layouts are no longer stored as third party settings,     // this will be handled by the code in     // \Drupal\Core\Config\Entity\ConfigEntityBase::set() that handles     // \Drupal\Core\Entity\EntityWithPluginCollectionInterface.     $layout_settings = $this->doGetLayout($layout_id$layout_settings)->getConfiguration();
    $this->setThirdPartySetting('field_layout', 'settings', $layout_settings);
    return $this;
  }

  /** * Implements \Drupal\field_layout\Display\EntityDisplayWithLayoutInterface::setLayout(). */
    $this->rebuildContainer();

    \Drupal::configFactory()->getEditable('language.negotiation')
      ->set('url.prefixes.ca', 'ca')
      ->set('url.prefixes.ca-fr', 'ca-fr')
      ->save();

    ContentLanguageSettings::create([
      'target_entity_type_id' => 'node',
      'target_bundle' => 'article',
    ])
      ->setThirdPartySetting('content_translation', 'enabled', TRUE)
      ->save();

    $this->createDefaultContent(5, 5, TRUE, TRUE, static::IS_MULTILINGUAL, FALSE);
  }

  /** * Tests reading multilingual content. */
  public function testReadMultilingual() {
    // Different databases have different sort orders, so a sort is required so     // test expectations do not need to vary per database.
/** * {@inheritdoc} */
  public function isInstallable() {
    return $this->storage->isInstallable();
  }

  /** * {@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} */
'workflows',
    'workflow_type_test',
    'workflow_third_party_settings_test',
  ];

  /** * Tests \Drupal\workflows\Entity\Workflow::onDependencyRemoval(). */
  public function testOnDependencyRemoval() {
    // Create a workflow that has a dependency on a third party setting.     $workflow = Workflow::create(['id' => 'test3', 'type' => 'workflow_type_complex_test']);
    $workflow->setThirdPartySetting('workflow_third_party_settings_test', 'key', 'value');
    $workflow->save();
    $this->assertSame(['workflow_third_party_settings_test', 'workflow_type_test']$workflow->getDependencies()['module']);

    // Uninstall workflow_third_party_settings_test to ensure     // \Drupal\workflows\Entity\Workflow::onDependencyRemoval() works as     // expected.     \Drupal::service('module_installer')->uninstall(['node', 'workflow_third_party_settings_test']);
    /** @var \Drupal\workflows\WorkflowInterface $workflow */
    $workflow = \Drupal::entityTypeManager()->getStorage('workflow')->loadUnchanged($workflow->id());
    $this->assertSame(['workflow_type_test']$workflow->getDependencies()['module']);
  }

}
public function testConfigurableLayoutSections() {
    $layout_url = 'node/1/layout';

    \Drupal::entityTypeManager()
      ->getStorage('entity_view_display')
      ->create([
        'targetEntityType' => 'node',
        'bundle' => 'bundle_with_section_field',
        'mode' => 'full',
      ])
      ->enable()
      ->setThirdPartySetting('layout_builder', 'enabled', TRUE)
      ->setThirdPartySetting('layout_builder', 'allow_custom', TRUE)
      ->save();

    $assert_session = $this->assertSession();
    $page = $this->getSession()->getPage();

    $this->drupalGet($layout_url);
    $this->markCurrentPage();

    $assert_session->linkExists('Add section');
    $this->clickLink('Add section');
    
$entity = Action::create([
      'id' => 'third_party_settings_test',
      '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. */
    $trail = [];
    $this->assertBreadcrumb('node', $trail);

    // Verify node breadcrumbs (in menu).     // Do this separately for Main menu and Tools menu, since only the     // latter is a preferred menu by default.     // @todo Also test all themes? Manually testing led to the suspicion that     // breadcrumbs may differ, possibly due to theme overrides.     $menus = ['main', 'tools'];
    // Alter node type menu settings.     $node_type = NodeType::load($type);
    $node_type->setThirdPartySetting('menu_ui', 'available_menus', $menus);
    $node_type->setThirdPartySetting('menu_ui', 'parent', 'tools:');
    $node_type->save();

    foreach ($menus as $menu) {
      // Create a parent node in the current menu.       $title = $this->randomMachineName();
      $node2 = $this->drupalCreateNode([
        'type' => $type,
        'title' => $title,
        'menu' => [
          'enabled' => 1,
          
Home | Imprint | This part of the site doesn't use cookies.