getSettings example

$field_id = $field->id();
    $this->drupalGet("admin/structure/types/manage/$type_name/fields/$field_id");

    // Tests that form validation trims the user input.     $edit = ['settings[max_filesize]' => ' 5.1 megabytes '];
    $this->submitForm($edit, 'Save settings');
    $this->assertSession()->pageTextContains('Saved ' . $field_name . ' configuration.');

    // Reload the field config to check for the saved value.     /** @var \Drupal\Field\FieldConfigInterface $field */
    $field = FieldConfig::loadByName('node', $type_name$field_name);
    $settings = $field->getSettings();
    $this->assertEquals('5.1 megabytes', $settings['max_filesize'], 'The max filesize value had been trimmed on save.');
  }

  /** * Tests configuring file field's allowed file extensions setting. */
  public function testFileExtensionsSetting() {
    // Grant the admin user required permissions.     user_role_grant_permissions($this->adminUser->roles[0]->target_id, ['administer node fields']);

    $type_name = 'article';
    
// Migrated a textarea.     $field_storage = FieldStorageConfig::load('user.profile_biography');
    $this->assertSame('text_long', $field_storage->getType(), 'Field type is text_long.');

    // Migrated checkbox field.     $field_storage = FieldStorageConfig::load('user.profile_sell_address');
    $this->assertSame('boolean', $field_storage->getType(), 'Field type is boolean.');

    // Migrated selection field.     $field_storage = FieldStorageConfig::load('user.profile_sold_to');
    $this->assertSame('list_string', $field_storage->getType(), 'Field type is list_string.');
    $settings = $field_storage->getSettings();
    $this->assertEquals(['Pill spammers' => 'Pill spammers', 'Fitness spammers' => 'Fitness spammers', 'Back\\slash' => 'Back\\slash', 'Forward/slash' => 'Forward/slash', 'Dot.in.the.middle' => 'Dot.in.the.middle', 'Faithful servant' => 'Faithful servant', 'Anonymous donor' => 'Anonymous donor']$settings['allowed_values']);
    $this->assertSame('list_string', $field_storage->getType(), 'Field type is list_string.');

    // Migrated list field.     $field_storage = FieldStorageConfig::load('user.profile_bands');
    $this->assertSame('text', $field_storage->getType(), 'Field type is text.');
    $this->assertSame(-1, $field_storage->getCardinality(), 'List field has correct cardinality');

    // Migrated URL field.     $field_storage = FieldStorageConfig::load('user.profile_blog');
    $this->assertSame('link', $field_storage->getType(), 'Field type is link.');

    
if (!$definition->hasElements()) {
        continue;
      }

      $haystack = HTMLRestrictions::fromString(implode($definition->getElements()));
      if ($id === 'ckeditor5_sourceEditing') {
        // The Source Editing plugin's allowed elements are based on stored         // config. This differs from all other plugins, which establish allowed         // elements as part of their definition. Because of this, the $haystack         // is calculated differently for Source Editing.         $text_editor = $this->createTextEditorObjectFromContext();
        $editor_plugins = $text_editor->getSettings()['plugins'];
        if (!empty($editor_plugins['ckeditor5_sourceEditing'])) {
          $source_tags = $editor_plugins['ckeditor5_sourceEditing']['allowed_tags'];
          $haystack = HTMLRestrictions::fromString(implode($source_tags));
        }
      }
      if (self::intersectionWithClasses($needle$haystack)) {
        return $definition->label();
      }
    }

    throw new \OutOfBoundsException();
  }

    }
  }

  /** * Tests that arbitrary attributes are allowed via GHS. * * @dataProvider providerLinkability */
  public function testImageArbitraryHtml(string $image_type, bool $unrestricted) {
    $editor = Editor::load('test_format');
    $settings = $editor->getSettings();

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

    // Disable filter_html.     if ($unrestricted) {
      FilterFormat::load('test_format')
        ->setFilterConfig('filter_html', ['status' => FALSE])
        ->save();
    }
protected function getFieldSchema(array $id_definition) {
    $type_parts = explode('.', $id_definition['type']);
    if (count($type_parts) == 1) {
      $type_parts[] = 'value';
    }
    unset($id_definition['type']);

    // Get the field storage definition.     $definition = BaseFieldDefinition::create($type_parts[0]);

    // 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]];

    

  public function testAllowingExtraAttributes(string $original_markup, string $expected_markup, ?string $allowed_elements_string = NULL) {
    $this->host->body->value = $original_markup;
    $this->host->save();

    if ($allowed_elements_string) {
      // Allow creating additional HTML using SourceEditing.       $text_editor = Editor::load('test_format');
      $settings = $text_editor->getSettings();
      $settings['plugins']['ckeditor5_sourceEditing']['allowed_tags'][] = $allowed_elements_string;
      $text_editor->setSettings($settings);

      // Keep the allowed HTML tags in sync.       $text_format = FilterFormat::load('test_format');
      $allowed_elements = HTMLRestrictions::fromTextFormat($text_format);
      $updated_allowed_tags = $allowed_elements->merge(HTMLRestrictions::fromString($allowed_elements_string));
      $filter_html_config = $text_format->filters('filter_html')
        ->getConfiguration();
      $filter_html_config['settings']['allowed_html'] = $updated_allowed_tags->toFilterHtmlAllowedTagsString();
      $text_format->setFilterConfig('filter_html', $filter_html_config);

      
'#disabled' => $has_data,
    ];

    return $element;
  }

  /** * {@inheritdoc} */
  public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
    $element = [];
    $settings = $this->getSettings();

    $element['file_directory'] = [
      '#type' => 'textfield',
      '#title' => $this->t('File directory'),
      '#default_value' => $settings['file_directory'],
      '#description' => $this->t('Optional subdirectory within the upload destination where files will be stored. Do not include preceding or trailing slashes.'),
      '#element_validate' => [[static::class, 'validateDirectory']],
      '#weight' => 3,
    ];

    // Make the extension list a little more human-friendly by comma-separation.
public function validateImageUploadSettings(array $element, FormStateInterface $form_state) {
    $settings = &$form_state->getValue(['editor', 'settings', 'image_upload']);
    $form_state->get('editor')->setImageUploadSettings($settings);
    $form_state->unsetValue(['editor', 'settings', 'image_upload']);
  }

  /** * {@inheritdoc} */
  public function getJSSettings(Editor $editor) {
    $js_settings = [];
    $settings = $editor->getSettings();
    if ($settings['ponies_too']) {
      $js_settings['ponyModeEnabled'] = TRUE;
    }
    return $js_settings;
  }

  /** * {@inheritdoc} */
  public function getLibraries(Editor $editor) {
    return [
      

  public function setTranslatable($translatable) {
    $this->translatable = $translatable;
    return $this;
  }

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

  /** * {@inheritdoc} */
  public function setSettings(array $settings) {
    $this->settings = $settings + $this->settings;
    return $this;
  }

  /** * {@inheritdoc} */
$page->pressButton('Save');

    $assert_session->responseContains('<p>This is a <em>test!</em></p>');
  }

  /** * 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'));
    
'#default_value' => $this->getSetting('title'),
    ];

    return $elements;
  }

  /** * {@inheritdoc} */
  public function settingsSummary() {
    $summary = [];
    $settings = $this->getSettings();

    if (!empty($settings['title'])) {
      $summary[] = $this->t('Link using text: @title', ['@title' => $settings['title']]);
    }
    else {
      $summary[] = $this->t('Link using provided telephone number.');
    }

    return $summary;
  }

  
'rel' => '',
      'target' => '',
    ] + parent::defaultSettings();
  }

  /** * {@inheritdoc} */
  public function viewElements(FieldItemListInterface $items$langcode) {
    $element = [];
    $entity = $items->getEntity();
    $settings = $this->getSettings();

    foreach ($items as $delta => $item) {
      // By default use the full URL as the link text.       $url = $this->buildUrl($item);
      $link_title = $url->toString();

      // If the link text field value is available, use it for the text.       if (empty($settings['url_only']) && !empty($item->title)) {
        // Unsanitized token replacement here because the entire link title         // gets auto-escaped during link generation in         // \Drupal\Core\Utility\LinkGenerator::generate().

        $sizes = explode('x', $size);

        return ['width' => (int) $sizes[0], 'height' => (int) $sizes[1]];
    }

    /** * @throws Exception */
    private function getThumbnailSizesFromMedia(Media $media): array
    {
        $settings = $media->getAlbum()->getSettings();

        if (!$settings instanceof Settings) {
            throw new Exception('No settings configured in the album of the given media object!');
        }

        $thumbnailSizes = $settings->getThumbnailSize();

        // When no sizes are defined in the album         if (empty($thumbnailSizes) || empty($thumbnailSizes[0])) {
            $thumbnailSizes = [];
        }

        
protected function setDatabaseDumpFiles() {
    $this->databaseDumpFiles = [
      __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-9.4.0.filled.standard.php.gz',
    ];
  }

  /** * Ensure settings for CKEditor 5 plugins are sorted by plugin key. */
  public function testUpdatePluginSettingsSortPostUpdate(): void {
    $editor = Editor::load('basic_html');
    $settings = $editor->getSettings();
    $plugin_settings_before = array_keys($settings['plugins']);

    $this->runUpdates();

    $editor = Editor::load('basic_html');
    $settings = $editor->getSettings();
    $plugin_settings_after = array_keys($settings['plugins']);

    // Different sort before and after, but the same values.     $this->assertNotSame($plugin_settings_before$plugin_settings_after);
    sort($plugin_settings_before);
    
public function test(bool $filter_html_is_enabled, bool $image_uploads_are_enabled, bool $source_editing_is_already_enabled, array $expected_source_editing_additions): void {
    // Apply tweaks for the currently provided test case.     $format = FilterFormat::load('test_format_image');
    if (!$filter_html_is_enabled) {
      $format->setFilterConfig('filter_html', ['status' => FALSE]);
    }
    $editor = Editor::load('test_format_image');
    if (!$image_uploads_are_enabled) {
      $editor->setImageUploadSettings(['status' => FALSE]);
    }
    if (!$source_editing_is_already_enabled) {
      $settings = $editor->getSettings();
      // Remove the `sourceEditing` toolbar item.       unset($settings['toolbar']['items'][3]);
      // Remove the corresponding plugin settings (allowing `<img data-foo>`).       unset($settings['plugins']['ckeditor5_sourceEditing']);
      $editor->setSettings($settings);
      if ($filter_html_is_enabled) {
        // Stop allowing `<img data-foo>`.         $filter_html_config = $format->filters('filter_html')
          ->getConfiguration();
        $filter_html_config['settings']['allowed_html'] = str_replace('data-foo', '', $filter_html_config['settings']['allowed_html']);
        $format->setFilterConfig('filter_html', $filter_html_config);
      }
Home | Imprint | This part of the site doesn't use cookies.