getThirdPartySettings example

'#view_mode' => $this->viewMode,
        '#language' => $items->getLangcode(),
        '#field_name' => $field_name,
        '#field_type' => $this->fieldDefinition->getType(),
        '#field_translatable' => $this->fieldDefinition->isTranslatable(),
        '#entity_type' => $entity_type,
        '#bundle' => $entity->bundle(),
        '#object' => $entity,
        '#items' => $items,
        '#formatter' => $this->getPluginId(),
        '#is_multiple' => $this->fieldDefinition->getFieldStorageDefinition()->isMultiple(),
        '#third_party_settings' => $this->getThirdPartySettings(),
      ];

      $elements = array_merge($info$elements);
    }

    return $elements;
  }

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

    // Test getThirdPartyProviders().     $this->entity->setThirdPartySetting('test_provider2', $key$value);
    $this->assertEquals([$third_party, 'test_provider2']$this->entity->getThirdPartyProviders());

    // Test unsetThirdPartyProviders().     $this->entity->unsetThirdPartySetting('test_provider2', $key);
    $this->assertEquals([$third_party]$this->entity->getThirdPartyProviders());
  }

  /** * @covers ::toArray */
$this->assertSame([$entity_1->id()$entity_4->id()$entity_2->id()]array_keys($called), 'The most dependent entities have ConfigEntityInterface::onDependencyRemoval() called first.');
    $this->assertSame(['config' => [], 'content' => [], 'module' => ['node'], 'theme' => []]$called[$entity_1->id()]);
    $this->assertSame(['config' => [], 'content' => [], 'module' => ['node'], 'theme' => []]$called[$entity_2->id()]);
    $this->assertSame(['config' => [], 'content' => [], 'module' => ['node'], 'theme' => []]$called[$entity_4->id()]);

    // Perform the uninstall.     $config_manager->uninstall('module', 'node');

    // Test that expected actions have been performed.     $entity_1 = $storage->load($entity_1->id());
    $this->assertNotEmpty($entity_1, 'Entity 1 not deleted');
    $this->assertSame($entity_1->getThirdPartySettings('node')[], 'Entity 1 third party settings updated.');
    $entity_2 = $storage->load($entity_2->id());
    $this->assertNotEmpty($entity_2, 'Entity 2 not deleted');
    $this->assertSame($entity_2->getThirdPartySettings('node')[], 'Entity 2 third party settings updated.');
    $this->assertSame($entity_2->calculateDependencies()->getDependencies()['config'][$entity_1->getConfigDependencyName()], 'Entity 2 still depends on entity 1.');
    $entity_3 = $storage->load($entity_3->id());
    $this->assertNotEmpty($entity_3, 'Entity 3 not deleted');
    $this->assertSame($entity_3->calculateDependencies()->getDependencies()['config'][$entity_2->getConfigDependencyName()], 'Entity 3 still depends on entity 2.');
    $this->assertNull($storage->load($entity_4->id()), 'Entity 4 deleted');
  }

  /** * Tests deleting a configuration entity and dependency management. */
/** * {@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} */
  public function unsetThirdPartySetting($module$key) {
    return $this->storage->unsetThirdPartySetting($module$key);
  }

  /** * {@inheritdoc} */
$changed = TRUE;
        }

        // Give this component the opportunity to react on dependency removal.         $component_removed_dependencies = $this->getPluginRemovedDependencies($renderer->calculateDependencies()$dependencies);
        if ($component_removed_dependencies) {
          if ($renderer->onDependencyRemoval($component_removed_dependencies)) {
            // Update component settings to reflect changes.             $component['settings'] = $renderer->getSettings();
            $component['third_party_settings'] = [];
            foreach ($renderer->getThirdPartyProviders() as $module) {
              $component['third_party_settings'][$module] = $renderer->getThirdPartySettings($module);
            }
            $this->setComponent($name$component);
            $changed = TRUE;
          }
          // If there are unresolved deleted dependencies left, disable this           // component to avoid the removal of the entire display entity.           if ($this->getPluginRemovedDependencies($renderer->calculateDependencies()$dependencies)) {
            $this->removeComponent($name);
            $arguments = [
              '@display' => (string) $this->getEntityType()->getLabel(),
              '@id' => $this->id(),
              
/** * @coversDefaultClass \Drupal\Core\Field\PluginSettingsBase * @group Field */
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() {
  }

  public function assertLanguageContentSettings(string $target_entity, string $bundle, string $default_langcode, bool $language_alterable, array $third_party_settings): void {
    $config = ContentLanguageSettings::load($target_entity . '.' . $bundle);
    $this->assertInstanceOf(ContentLanguageSettings::class$config);
    $this->assertSame($target_entity$config->getTargetEntityTypeId());
    $this->assertSame($bundle$config->getTargetBundle());
    $this->assertSame($default_langcode$config->getDefaultLangcode());
    $this->assertSame($language_alterable$config->isLanguageAlterable());
    $this->assertSame($third_party_settings$config->getThirdPartySettings('content_translation'));
  }

}

  public function assertLanguageContentSettings(string $target_entity, string $bundle, string $default_langcode, bool $language_alterable, array $third_party_settings): void {
    $config = ContentLanguageSettings::load($target_entity . "." . $bundle);
    $this->assertInstanceOf(ContentLanguageSettings::class$config);
    $this->assertSame($target_entity$config->getTargetEntityTypeId());
    $this->assertSame($bundle$config->getTargetBundle());
    $this->assertSame($default_langcode$config->getDefaultLangcode());
    $this->assertSame($language_alterable$config->isLanguageAlterable());
    $this->assertSame($third_party_settings$config->getThirdPartySettings('content_translation'));
  }

}
protected function assertComponents(array $expected, Section $section): void {
    $result = $section->getComponents();
    $this->assertEquals($expected$result);
    $this->assertSame(array_keys($expected)array_keys($result));
  }

  /** * @covers ::getThirdPartySettings * @dataProvider providerTestGetThirdPartySettings */
  public function testGetThirdPartySettings($provider$expected) {
    $this->assertSame($expected$this->section->getThirdPartySettings($provider));
  }

  /** * Provides test data for ::testGetThirdPartySettings(). */
  public function providerTestGetThirdPartySettings() {
    $data = [];
    $data[] = [
      'bad_judgement',
      ['blink_speed' => 'fast', 'spin_direction' => 'clockwise'],
    ];
    
/** * {@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} */
  public function unsetThirdPartySetting($module$key) {
    $this->getDisplay()->unsetThirdPartySetting($module$key);
    return $this;
  }

  /** * {@inheritdoc} */
$this->assertInstanceOf(EntityContext::class$result['display']);
      /** @var \Drupal\Core\Plugin\Context\EntityContext $display_entity_context */
      $display_entity_context = $result['display'];

      /** @var \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay $display_entity */
      $display_entity = $display_entity_context->getContextData()->getValue();
      $this->assertInstanceOf(LayoutBuilderEntityViewDisplay::class$display_entity);

      $this->assertEquals('full', $display_entity->getMode());
      $this->assertEquals($expected_display->getEntityTypeId()$display_entity->getEntityTypeId());
      $this->assertEquals($expected_display->getComponents()$display_entity->getComponents());
      $this->assertEquals($expected_display->getThirdPartySettings('layout_builder')$display_entity->getThirdPartySettings('layout_builder'));
    }
    else {
      throw new \UnexpectedValueException("Unexpected entity type.");
    }

  }

  /** * Data provider for testOriginalEntityUsesDefaultStorage(). */
  public function providerTestOriginalEntityUsesDefaultStorage() {
    
$this->assertInstanceOf(ContentLanguageSettings::class$config);
    $this->assertSame('menu_link_content', $config->getTargetEntityTypeId());
    $this->assertSame('menu_link_content', $config->getTargetBundle());
    $this->assertSame(LanguageInterface::LANGCODE_SITE_DEFAULT, $config->getDefaultLangcode());
    $this->assertTrue($config->isLanguageAlterable());
    $settings = [
      'enabled' => TRUE,
      'bundle_settings' => [
        'untranslatable_fields_hide' => '0',
      ],
    ];
    $this->assertSame($settings$config->getThirdPartySettings('content_translation'));
  }

}
Home | Imprint | This part of the site doesn't use cookies.