isApplicable example

    // being moderated.     $entity_form_display->extractFormValues($entity$form$form_state);
    $this->assertEquals(0, $entity->moderation_state->count());
  }

  /** * @covers ::isApplicable */
  public function testIsApplicable() {
    // The moderation_state field definition should be applicable to our widget.     $fields = $this->container->get('entity_field.manager')->getFieldDefinitions('node', 'test_type');
    $this->assertTrue(ModerationStateWidget::isApplicable($fields['moderation_state']));
    $this->assertFalse(ModerationStateWidget::isApplicable($fields['status']));
    // A config override should still be applicable.     $field_config = $fields['moderation_state']->getConfig('moderated');
    $this->assertTrue(ModerationStateWidget::isApplicable($field_config));
  }

}

class FileSize extends FormatterBase {

  /** * {@inheritdoc} */
  public static function isApplicable(FieldDefinitionInterface $field_definition) {
    return parent::isApplicable($field_definition) && $field_definition->getName() === 'filesize';
  }

  /** * {@inheritdoc} */
  public function viewElements(FieldItemListInterface $items$langcode) {
    $elements = [];

    foreach ($items as $delta => $item) {
      $elements[$delta] = ['#markup' => format_size($item->value)];
    }

    

  public function findByContext(array $contexts, RefinableCacheableDependencyInterface $cacheability) {
    $storage_types = array_keys($this->contextHandler->filterPluginDefinitionsByContexts($contexts$this->getDefinitions()));

    // Add the manager as a cacheable dependency in order to vary by changes to     // the plugin definitions.     $cacheability->addCacheableDependency($this);

    foreach ($storage_types as $type) {
      $plugin = $this->load($type$contexts);
      if ($plugin && $plugin->isApplicable($cacheability)) {
        return $plugin;
      }
    }
    return NULL;
  }

  /** * {@inheritdoc} */
  public function loadEmpty($type) {
    return $this->createInstance($type);
  }
    if (!isset($options['prepare']) || $options['prepare'] == TRUE) {
      $configuration = $this->prepareConfiguration($field_type$configuration);
    }

    $plugin_id = $configuration['type'];

    // Switch back to default formatter if either:     // - the configuration does not specify a formatter class     // - the field type is not allowed for the formatter     // - the formatter is not applicable to the field definition.     $definition = $this->getDefinition($configuration['type'], FALSE);
    if (!isset($definition['class']) || !in_array($field_type$definition['field_types']) || !$definition['class']::isApplicable($field_definition)) {
      // Grab the default widget for the field type.       $field_type_definition = $this->fieldTypeManager->getDefinition($field_type);
      if (empty($field_type_definition['default_formatter'])) {
        return FALSE;
      }
      $plugin_id = $field_type_definition['default_formatter'];
    }

    $configuration += [
      'field_definition' => $field_definition,
      'view_mode' => $options['view_mode'],
    ];

        return $extension;
      }
    }
  }

  /** * {@inheritdoc} */
  public static function isApplicable(FieldDefinitionInterface $field_definition) {
    // Just show this file extension formatter on the filename field.     return parent::isApplicable($field_definition) && $field_definition->getName() === 'filename';
  }

}
try {
        $sa = SecurityAdvisory::createFromArray($advisory_data);
      }
      catch (\UnexpectedValueException $unexpected_value_exception) {
        // Ignore items in the feed that are in an invalid format. Although         // this is highly unlikely we should still display the items that are         // in the correct format.         Error::logException($this->logger, $unexpected_value_exception, 'Invalid security advisory format: @advisory', ['@advisory' => Json::encode($advisory_data)]);
        continue;
      }

      if ($this->isApplicable($sa)) {
        $advisories[] = $sa;
      }
    }
    return $advisories;
  }

  /** * Deletes the stored JSON feed response, if any. */
  public function deleteStoredResponse(): void {
    $this->keyValueExpirable->delete(self::ADVISORIES_JSON_EXPIRABLE_KEY);
  }
$contexts = [
      'foo' => new Context(new ContextDefinition('foo')),
    ];
    $definitions = [
      'no_access' => (new SectionStorageDefinition())->setClass(SectionStorageInterface::class),
      'missing_contexts' => (new SectionStorageDefinition())->setClass(SectionStorageInterface::class),
      'provider_access' => (new SectionStorageDefinition())->setClass(SectionStorageInterface::class),
    ];
    $this->discovery->getDefinitions()->willReturn($definitions);

    $provider_access = $this->prophesize(SectionStorageInterface::class);
    $provider_access->isApplicable($cacheability)->willReturn($plugin_is_applicable);

    $no_access = $this->prophesize(SectionStorageInterface::class);
    $no_access->isApplicable($cacheability)->willReturn(FALSE);

    $missing_contexts = $this->prophesize(SectionStorageInterface::class);

    // Do not do any filtering based on context.     $this->contextHandler->filterPluginDefinitionsByContexts($contexts$definitions)->willReturnArgument(1);
    $this->contextHandler->applyContextMapping($no_access$contexts)->shouldBeCalled();
    $this->contextHandler->applyContextMapping($provider_access$contexts)->shouldBeCalled();
    $this->contextHandler->applyContextMapping($missing_contexts$contexts)->willThrow(new ContextException());

    

  protected function getApplicableEntityTypes() {
    $entity_types = $this->entityTypeManager->getDefinitions();
    $entity_types = array_filter($entity_typesfunction DEntityTypeInterface $entity_type) {
      return $this->isApplicable($entity_type);
    });

    return $entity_types;
  }

}


    return $element;
  }

  /** * {@inheritdoc} */
  public static function isApplicable(FieldDefinitionInterface $field_definition) {
    $target_bundle = $field_definition->getTargetBundle();

    if (!parent::isApplicable($field_definition) || $field_definition->getTargetEntityTypeId() !== 'media' || !$target_bundle) {
      return FALSE;
    }
    return MediaType::load($target_bundle)->getSource() instanceof OEmbedInterface;
  }

}
return $summary;
  }

  /** * {@inheritdoc} */
  public static function isApplicable(FieldDefinitionInterface $field_definition) {
    if ($field_definition->getTargetEntityTypeId() !== 'media') {
      return FALSE;
    }

    if (parent::isApplicable($field_definition)) {
      $media_type = $field_definition->getTargetBundle();

      if ($media_type) {
        $media_type = MediaType::load($media_type);
        return $media_type && $media_type->getSource() instanceof OEmbedInterface;
      }
    }
    return FALSE;
  }

}
$value = $item->value;
    if ($this->getSetting('file_download_path')) {
      $value = $this->fileUrlGenerator->generateString($value);
    }
    return $value;
  }

  /** * {@inheritdoc} */
  public static function isApplicable(FieldDefinitionInterface $field_definition) {
    return parent::isApplicable($field_definition) && $field_definition->getName() === 'uri';
  }

}
    if ($options['prepare']) {
      $configuration = $this->prepareConfiguration($field_type$configuration);
    }

    $plugin_id = $configuration['type'];

    // Switch back to default widget if either:     // - the configuration does not specify a widget class     // - the field type is not allowed for the widget     // - the widget is not applicable to the field definition.     $definition = $this->getDefinition($configuration['type'], FALSE);
    if (!isset($definition['class']) || !in_array($field_type$definition['field_types']) || !$definition['class']::isApplicable($field_definition)) {
      // Grab the default widget for the field type.       $field_type_definition = $this->fieldTypeManager->getDefinition($field_type);
      if (empty($field_type_definition['default_widget'])) {
        return FALSE;
      }
      $plugin_id = $field_type_definition['default_widget'];
    }

    $configuration += [
      'field_definition' => $field_definition,
    ];
    

  protected function getApplicablePluginOptions(FieldDefinitionInterface $field_definition) {
    $options = $this->formatterManager->getOptions($field_definition->getType());
    $applicable_options = [];
    foreach ($options as $option => $label) {
      $plugin_class = DefaultFactory::getPluginClass($option$this->formatterManager->getDefinition($option));
      if ($plugin_class::isApplicable($field_definition)) {
        $applicable_options[$option] = $label;
      }
    }
    return $applicable_options;
  }

  /** * Gets the formatter object. * * @param array $parents * The #parents of the element representing the formatter. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. * * @return \Drupal\Core\Field\FormatterInterface * The formatter object. */
$attributes = $comment_permalink->getOption('attributes') ?: [];
      $attributes += ['title' => Unicode::truncate($body, 128)];
      $comment_permalink->setOption('attributes', $attributes);
    }
    return $comment_permalink;
  }

  /** * {@inheritdoc} */
  public static function isApplicable(FieldDefinitionInterface $field_definition) {
    return parent::isApplicable($field_definition) && $field_definition->getTargetEntityTypeId() === 'comment' && $field_definition->getName() === 'subject';
  }

}

  protected function getApplicablePluginOptions(FieldDefinitionInterface $field_definition) {
    $options = $this->pluginManager->getOptions($field_definition->getType());
    $applicable_options = [];
    foreach ($options as $option => $label) {
      $plugin_class = DefaultFactory::getPluginClass($option$this->pluginManager->getDefinition($option));
      if ($plugin_class::isApplicable($field_definition)) {
        $applicable_options[$option] = $label;
      }
    }
    return $applicable_options;
  }

  /** * Returns the ID of the default widget or formatter plugin for a field type. * * @param string $field_type * The field type. * * @return string * The widget or formatter plugin ID. */
Home | Imprint | This part of the site doesn't use cookies.