isFallbackFormat example

->setComponent($field_name[
        'type' => $widget_type,
      ])
      ->save();
    $display_repository->getViewDisplay('entity_test', 'entity_test', 'full')
      ->setComponent($field_name)
      ->save();

    // Disable all text formats besides the plain text fallback format.     $this->drupalLogin($this->adminUser);
    foreach (filter_formats() as $format) {
      if (!$format->isFallbackFormat()) {
        $this->drupalGet('admin/config/content/formats/manage/' . $format->id() . '/disable');
        $this->submitForm([], 'Disable');
      }
    }
    $this->drupalLogin($this->webUser);

    // Display the creation form. Since the user only has access to one format,     // no format selector will be displayed.     $this->drupalGet('entity_test/add');
    $this->assertSession()->fieldValueEquals("{$field_name}[0][value]", '');
    $this->assertSession()->fieldNotExists("{$field_name}[0][format]");

    
$properties = parent::toArray();
    // The 'roles' property is only used during install and should never     // actually be saved.     unset($properties['roles']);
    return $properties;
  }

  /** * {@inheritdoc} */
  public function disable() {
    if ($this->isFallbackFormat()) {
      throw new \LogicException("The fallback text format '{$this->id()}' cannot be disabled.");
    }

    parent::disable();

    // Allow modules to react on text format deletion.     \Drupal::moduleHandler()->invokeAll('filter_format_disable', [$this]);

    // Clear the filter cache whenever a text format is disabled.     filter_formats_reset();

    
$this->assertSession()->pageTextContains($new_title);
    $this->assertSession()->pageTextNotContains($old_title);

    // Switch the text format to a new one, then disable that format and all     // other formats on the site (leaving only the fallback format).     $this->drupalLogin($this->adminUser);
    $edit = [$body_format_key => $this->allowedFormat->id()];
    $this->drupalGet('node/' . $node->id() . '/edit');
    $this->submitForm($edit, 'Save');
    $this->assertSession()->addressEquals('node/' . $node->id());
    foreach (filter_formats() as $format) {
      if (!$format->isFallbackFormat()) {
        $format->disable()->save();
      }
    }

    // Since there is now only one available text format, the widget for     // selecting a text format would normally not display when the content is     // edited. However, we need to verify that the filter administrator still     // is forced to make a conscious choice to reassign the text to a different     // format.     $this->drupalLogin($this->filterAdminUser);
    $old_title = $new_title;
    

class FilterFormatAccessControlHandler extends EntityAccessControlHandler {

  /** * {@inheritdoc} */
  protected function checkAccess(EntityInterface $filter_format$operation, AccountInterface $account) {
    /** @var \Drupal\filter\FilterFormatInterface $filter_format */

    // All users are allowed to use the fallback filter.     if ($operation == 'use') {
      if ($filter_format->isFallbackFormat()) {
        return AccessResult::allowed();
      }
      else {
        return AccessResult::allowedIfHasPermission($account$filter_format->getPermissionName());
      }
    }

    // The fallback format may not be disabled.     if ($operation == 'disable' && $filter_format->isFallbackFormat()) {
      return AccessResult::forbidden();
    }

    
return $header + parent::buildHeader();
  }

  /** * {@inheritdoc} */
  public function buildRow(EntityInterface $entity) {
    // Check whether this is the fallback text format. This format is available     // to all roles and cannot be disabled via the admin interface.     $row['label'] = $entity->label();
    $row['roles'] = [];
    if ($entity->isFallbackFormat()) {
      $fallback_choice = $this->configFactory->get('filter.settings')->get('always_show_fallback_choice');
      if ($fallback_choice) {
        $row['roles']['#markup'] = $this->t('All roles may use this format');
      }
      else {
        $row['roles']['#markup'] = $this->t('This format is shown when no other formats are available');
      }
      // Emphasize the fallback role text since it is important to understand       // how it works which configuring filter formats. Additionally, it is not       // a list of roles unlike the other values in this column.       $row['roles']['#prefix'] = '<em>';
      
Home | Imprint | This part of the site doesn't use cookies.