setSettings example

/** * Tests that arbitrary attributes are allowed via GHS. */
  public function testEmphasisArbitraryHtml() {
    $assert_session = $this->assertSession();
    $editor = Editor::load('test_format');
    $settings = $editor->getSettings();

    // Allow the data-foo attribute in img via GHS.     $settings['plugins']['ckeditor5_sourceEditing']['allowed_tags'] = ['<em data-foo>'];
    $editor->setSettings($settings);
    $editor->save();

    // Add data-foo use to an existing em tag.     $original_value = $this->host->body->value;
    $this->host->body->value = str_replace('<em>', '<em data-foo="bar">', $original_value);
    $this->host->save();
    $this->drupalGet($this->host->toUrl('edit-form'));
    $this->waitForEditor();

    $emphasis_element = $assert_session->waitForElementVisible('css', '.ck-content p em');
    $this->assertEquals('bar', $emphasis_element->getAttribute('data-foo'));

    
NestedArray::setValue($basic_html_format_with_media_embed$allowed_html_parents$new_value);
    FilterFormat::create($basic_html_format_with_media_embed)->setSyncing(TRUE)->save();
    $basic_html_editor_with_media_embed = Editor::create(
      ['format' => 'basic_html_with_media_embed']
      +
      Yaml::parseFile('core/modules/ckeditor5/tests/fixtures/ckeditor4_config/editor.editor.basic_html.yml')
    );
    $settings = $basic_html_editor_with_media_embed->getSettings();
    // Add "insert media from library" button to CKEditor 4 configuration, the     // pre-existing toolbar item group labeled "Media".     $settings['toolbar']['rows'][0][3]['items'][] = 'DrupalMediaLibrary';
    $basic_html_editor_with_media_embed->setSettings($settings);
    $basic_html_editor_with_media_embed->setSyncing(TRUE)->save();

    $basic_html_format_with_media_embed_view_mode_invalid = $basic_html_format_with_media_embed;
    $basic_html_format_with_media_embed_view_mode_invalid['name'] = ' (with Media Embed support, view mode enabled but no view modes configured)';
    $basic_html_format_with_media_embed_view_mode_invalid['format'] = 'basic_html_with_media_embed_view_mode_enabled_no_view_modes_configured';
    $current_value_media_embed = NestedArray::getValue($basic_html_format_with_media_embed$allowed_html_parents);
    $new_value = str_replace('<drupal-media data-entity-type data-entity-uuid data-align data-caption alt>', '<drupal-media data-entity-type data-entity-uuid data-align data-caption alt data-view-mode>', $current_value_media_embed);
    NestedArray::setValue($basic_html_format_with_media_embed_view_mode_invalid$allowed_html_parents$new_value);
    FilterFormat::create($basic_html_format_with_media_embed_view_mode_invalid)->setSyncing(TRUE)->save();
    $basic_html_editor_with_media_embed_view_mode_enabled_no_view_modes_configured = Editor::create(
      ['format' => 'basic_html_with_media_embed_view_mode_enabled_no_view_modes_configured']
      +


    if ($settings !== FALSE) {
      // Attached settings override both library definitions and       // hook_js_settings_build().       $settings = NestedArray::mergeDeepArray([$settings$assets->getSettings()], TRUE);
      // Allow modules and themes to alter the JavaScript settings.       $this->moduleHandler->alter('js_settings', $settings$assets);
      $this->themeManager->alter('js_settings', $settings$assets);
      // Update the $assets object accordingly, so that it reflects the final       // settings.       $assets->setSettings($settings);
      $settings_as_inline_javascript = [
        'type' => 'setting',
        'group' => JS_SETTING,
        'weight' => 0,
        'data' => $settings,
      ];
      $settings_js_asset = ['drupalSettings' => $settings_as_inline_javascript];
      // Prepend to the list of JS assets, to render it first. Preferably in       // the footer, but in the header if necessary.       if ($settings_in_header) {
        $js_assets_header = $settings_js_asset + $js_assets_header;
      }

  public function testAddJsSettings() {
    // Add a file in order to test default settings.     $build['#attached']['library'][] = 'core/drupalSettings';
    $assets = AttachedAssets::createFromRenderArray($build);

    $this->assertEquals([]$assets->getSettings(), 'JavaScript settings on $assets are empty.');
    $javascript = $this->assetResolver->getJsAssets($assets, FALSE, \Drupal::languageManager()->getCurrentLanguage())[1];
    $this->assertArrayHasKey('currentPath', $javascript['drupalSettings']['data']['path']);
    $this->assertArrayHasKey('currentPath', $assets->getSettings()['path']);

    $assets->setSettings(['drupal' => 'rocks', 'dries' => 280342800]);
    $javascript = $this->assetResolver->getJsAssets($assets, FALSE, \Drupal::languageManager()->getCurrentLanguage())[1];
    $this->assertEquals(280342800, $javascript['drupalSettings']['data']['dries'], 'JavaScript setting is set correctly.');
    $this->assertEquals('rocks', $javascript['drupalSettings']['data']['drupal'], 'The other JavaScript setting is set correctly.');
  }

  /** * Tests adding external CSS and JavaScript files. */
  public function testAddExternalFiles() {
    $build['#attached']['library'][] = 'common_test/external';
    $assets = AttachedAssets::createFromRenderArray($build);

    
$fields['menu_name'] = BaseFieldDefinition::create('string')
      ->setLabel(t('Menu name'))
      ->setDescription(t('The menu name. All links with the same menu name (such as "tools") are part of the same menu.'))
      ->setDefaultValue('tools')
      ->setSetting('is_ascii', TRUE);

    $fields['link'] = BaseFieldDefinition::create('link')
      ->setLabel(t('Link'))
      ->setDescription(t('The location this menu link points to.'))
      ->setRevisionable(TRUE)
      ->setRequired(TRUE)
      ->setSettings([
        'link_type' => LinkItemInterface::LINK_GENERIC,
        'title' => DRUPAL_DISABLED,
      ])
      ->setDisplayOptions('form', [
        'type' => 'link_default',
        'weight' => -2,
      ]);

    $fields['external'] = BaseFieldDefinition::create('boolean')
      ->setLabel(t('External'))
      ->setDescription(t('A flag to indicate if the link points to a full URL starting with a protocol, like http:// (1 = external, 0 = internal).'))
      

  public function testMediaArbitraryHtml() {
    $assert_session = $this->assertSession();

    $editor = Editor::load('test_format');
    $settings = $editor->getSettings();

    // Allow the data-foo attribute in drupal-media via GHS. Also, add support     // for div's with data-foo attribute to ensure that drupal-media elements     // can be wrapped with other block elements.     $settings['plugins']['ckeditor5_sourceEditing']['allowed_tags'] = ['<drupal-media data-foo>', '<div data-bar>'];
    $editor->setSettings($settings);
    $editor->save();

    $filter_format = $editor->getFilterFormat();
    $filter_format->setFilterConfig('filter_html', [
      'status' => TRUE,
      'settings' => [
        'allowed_html' => '<p> <br> <strong> <em> <a href> <drupal-media data-entity-type data-entity-uuid data-align data-caption alt data-foo data-view-mode> <div data-bar>',
      ],
    ]);
    $filter_format->save();
    $this->assertSame([]array_map(
      
'changeable' => 'a changeable field storage setting',
      'unchangeable' => 'an unchangeable field storage setting',
      'translatable_storage_setting' => 'a translatable field storage setting',
      'test_field_setting' => 'dummy test string',
      'translatable_field_setting' => 'a translatable field setting',
    ];
    $this->assertEquals($expected_settings$base_field->getSettings());

    // Change one single setting using setSettings(), and check that the other     // expected settings are still present.     $expected_settings['test_field_setting'] = 'another test string';
    $base_field->setSettings(['test_field_setting' => $expected_settings['test_field_setting']]);
    $this->assertEquals($expected_settings$base_field->getSettings());
  }

  /** * Tests the base field settings on a cloned base field definition object. */
  public function testBaseFieldSettingsOnClone() {
    $base_field = BaseFieldDefinition::create('test_field');

    // Check that the default settings have been populated.     $expected_settings = [
      
// Get a list of setting keys belonging strictly to the field definition.     $default_field_settings = $definition->getSettings();
    // Separate field definition settings from custom settings. Custom settings     // are settings passed in $id_definition that are not part of field storage     // definition settings.     $field_settings = array_intersect_key($id_definition$default_field_settings);
    $custom_settings = array_diff_key($id_definition$default_field_settings);

    // Resolve schema from field storage definition settings.     $schema = $definition
      ->setSettings($field_settings)
      ->getColumns()[$type_parts[1]];

    // Merge back custom settings.     return $schema + $custom_settings;
  }

  /** * {@inheritdoc} */
  public function getRowBySource(array $source_id_values) {
    $query = $this->getDatabase()->select($this->mapTableName(), 'map')
      
$this->assertCount($expected_cache_item_count$this->cache->getAllCids());

    $this->assetResolver->getJsAssets($assets_a, FALSE, $this->japanese);
    $this->assetResolver->getJsAssets($assets_b, FALSE, $this->japanese);
    $this->assertCount($expected_cache_item_count * 2, $this->cache->getAllCids());
  }

  public function providerAttachedAssets() {
    $time = time();
    return [
      'same libraries, different timestamps' => [
        (new AttachedAssets())->setAlreadyLoadedLibraries([])->setLibraries(['core/drupal'])->setSettings(['currentTime' => $time]),
        (new AttachedAssets())->setAlreadyLoadedLibraries([])->setLibraries(['core/drupal'])->setSettings(['currentTime' => $time + 100]),
        1,
      ],
      'different libraries, same timestamps' => [
        (new AttachedAssets())->setAlreadyLoadedLibraries([])->setLibraries(['core/drupal'])->setSettings(['currentTime' => $time]),
        (new AttachedAssets())->setAlreadyLoadedLibraries([])->setLibraries(['core/drupal', 'core/jquery'])->setSettings(['currentTime' => $time]),
        2,
      ],
    ];
  }

}
continue;
        }
      }

      // Send this embedded HTML response.       $this->sendChunk($html_response);

      // Another placeholder was rendered and sent, track the set of asset       // libraries sent so far. Any new settings also need to be tracked, so       // they can be sent in ::sendPreBody().       $cumulative_assets->setAlreadyLoadedLibraries(array_merge($cumulative_assets->getAlreadyLoadedLibraries()$html_response->getAttachments()['library']));
      $cumulative_assets->setSettings($html_response->getAttachments()['drupalSettings']);

      // If there are multiple occurrences of this particular placeholder, track       // the content that was sent, so we can skip all calculations for the next       // occurrence.       if ($placeholder_occurrences[$fragment] > 1) {
        $multi_occurrence_placeholders_content[$fragment] = $html_response->getContent();
      }
    }
  }

  /** * Sends BigPipe placeholders' replacements as embedded AJAX responses. * * @param array $placeholders * Associative array; the BigPipe placeholders. Keys are the BigPipe * placeholder IDs. * @param array $placeholder_order * Indexed array; the order in which the BigPipe placeholders must be sent. * Values are the BigPipe placeholder IDs. (These values correspond to keys * in $placeholders.) * @param \Drupal\Core\Asset\AttachedAssetsInterface $cumulative_assets * The cumulative assets sent so far; to be updated while rendering BigPipe * placeholders. * * @throws \Exception * If an exception is thrown during the rendering of a placeholder, it is * caught to allow the other placeholders to still be replaced. But when * error logging is configured to be verbose, the exception is rethrown to * simplify debugging. */

  public static function createFromRenderArray(array $render_array) {
    if (!isset($render_array['#attached'])) {
      throw new \LogicException('The render array has not yet been rendered, hence not all attachments have been collected yet.');
    }

    $assets = new static();
    if (isset($render_array['#attached']['library'])) {
      $assets->setLibraries($render_array['#attached']['library']);
    }
    if (isset($render_array['#attached']['drupalSettings'])) {
      $assets->setSettings($render_array['#attached']['drupalSettings']);
    }
    return $assets;
  }

  /** * {@inheritdoc} */
  public function setLibraries(array $libraries) {
    $this->libraries = array_unique($libraries);
    return $this;
  }

  
$source_editing_additions = HTMLRestrictions::emptySet();
    // Compute the appropriate settings based on the CKEditor 4 configuration     // if it exists.     $old_editor = $editor->id() ? Editor::load($editor->id()) : NULL;
    $old_editor_restrictions = $old_editor ? HTMLRestrictions::fromTextFormat($old_editor->getFilterFormat()) : HTMLRestrictions::emptySet();
    // @todo Remove in https://www.drupal.org/project/drupal/issues/3245351     if ($old_editor) {
      $editor->setImageUploadSettings($old_editor->getImageUploadSettings());
    }
    if ($old_editor && $old_editor->getEditor() === 'ckeditor') {
      [$upgraded_settings$messages] = $this->createSettingsFromCKEditor4($old_editor->getSettings(), HTMLRestrictions::fromTextFormat($old_editor->getFilterFormat()));
      $editor->setSettings($upgraded_settings);
      // *Before* determining which elements are still needed for this text       // format, ensure that all already enabled plugins that are configurable       // have valid settings.       // For all already enabled plugins, find the ones that are configurable,       // and add their default settings. For enabled plugins with element       // subsets, compute the appropriate settings to achieve the subset that       // matches the original text format restrictions.       $this->addDefaultSettingsForEnabledConfigurablePlugins($editor);
      $this->computeSubsetSettingForEnabledPluginsWithSubsets($editor$text_format);
    }

    
$form_state->setErrorByName('toolbar][items', $this->t('Invalid toolbar value.'));
      return;
    }

    // Construct a Text Editor config entity with the submitted values for     // validation. Do this on a clone: do not manipulate form state.     $submitted_editor = clone $form_state->get('editor');
    $settings = $submitted_editor->getSettings();
    // Update settings first to match the submitted toolbar items. This is     // necessary for ::shouldHaveVisiblePluginSettingsForm() to work.     $settings['toolbar']['items'] = $toolbar_items;
    $submitted_editor->setSettings($settings);
    $eventual_editor_and_format_for_plugin_settings_visibility = $this->getEventualEditorWithPrimedFilterFormat($form_state$submitted_editor);
    $settings['plugins'] = [];
    $default_configurations = [];
    foreach ($this->ckeditor5PluginManager->getDefinitions() as $plugin_id => $definition) {
      if (!$definition->isConfigurable()) {
        continue;
      }
      // Create a fresh instance of this CKEditor 5 plugin, not tied to a text       // editor configuration entity.       $plugin = $this->ckeditor5PluginManager->getPlugin($plugin_id, NULL);
      // If this plugin is configurable but it has empty default configuration,
// Aggregate CSS/JS if necessary, but only during normal site operation.     $optimize_css = !$maintenance_mode && $this->config->get('css.preprocess');
    $optimize_js = $maintenance_mode && $this->config->get('js.preprocess');

    $attachments = $response->getAttachments();

    // Resolve the attached libraries into asset collections.     $assets = new AttachedAssets();
    $assets->setLibraries($attachments['library'] ?? [])
      ->setAlreadyLoadedLibraries(isset($ajax_page_state['libraries']) ? explode(',', $ajax_page_state['libraries']) : [])
      ->setSettings($attachments['drupalSettings'] ?? []);
    $css_assets = $this->assetResolver->getCssAssets($assets$optimize_css$this->languageManager->getCurrentLanguage());
    [$js_assets_header$js_assets_footer] = $this->assetResolver->getJsAssets($assets$optimize_js$this->languageManager->getCurrentLanguage());

    // First, AttachedAssets::setLibraries() ensures duplicate libraries are     // removed: it converts it to a set of libraries if necessary. Second,     // AssetResolver::getJsSettings() ensures $assets contains the final set of     // JavaScript settings. AttachmentsResponseProcessorInterface also mandates     // that the response it processes contains the final attachment values, so     // update both the 'library' and 'drupalSettings' attachments accordingly.     $attachments['library'] = $assets->getLibraries();
    $attachments['drupalSettings'] = $assets->getSettings();
    

  public function setFieldStorageDefinition(FieldStorageDefinitionInterface $storageDefinition) {
    $this->fieldStorageDefinition = $storageDefinition;
    $this->itemDefinition = FieldItemDataDefinition::create($this);
    // Create a definition for the items, and initialize it with the default     // settings for the field type.     $field_type_manager = \Drupal::service('plugin.manager.field.field_type');
    $default_settings = $field_type_manager->getDefaultFieldSettings($storageDefinition->getType());
    $this->itemDefinition->setSettings($default_settings);
    return $this;
  }

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

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.