getPluginCollections example

/** * {@inheritdoc} */
  protected static $modules = ['entity_test'];

  /** * @covers ::copyFormValuesToEntity */
  public function testCopyFormValuesToEntity() {
    $field_values = [];
    $entity = $this->prophesize(EntityDisplayInterface::class);
    $entity->getPluginCollections()->willReturn([]);
    $entity->getTargetEntityTypeId()->willReturn('entity_test_with_bundle');
    $entity->getTargetBundle()->willReturn('target_bundle');

    // An initially hidden field, with a submitted region change.     $entity->getComponent('new_field_mismatch_type_visible')->willReturn([]);
    $field_values['new_field_mismatch_type_visible'] = [
      'weight' => 0,
      'type' => 'textfield',
      'region' => 'hidden',
    ];
    $entity->removeComponent('new_field_mismatch_type_visible')
      
protected function getResourcePluginManager() {
    if (!isset($this->pluginManager)) {
      $this->pluginManager = \Drupal::service('plugin.manager.rest');
    }
    return $this->pluginManager;
  }

  /** * {@inheritdoc} */
  public function getResourcePlugin() {
    return $this->getPluginCollections()['resource']->get($this->plugin_id);
  }

  /** * {@inheritdoc} */
  public function getMethods() {
    switch ($this->granularity) {
      case RestResourceConfigInterface::METHOD_GRANULARITY:
        return $this->getMethodsForMethodGranularity();

      case RestResourceConfigInterface::RESOURCE_GRANULARITY:
        

  public function get($property_name) {
    return $this->{$property_name} ?? NULL;
  }

  /** * {@inheritdoc} */
  public function set($property_name$value) {
    if ($this instanceof EntityWithPluginCollectionInterface) {
      $plugin_collections = $this->getPluginCollections();
      if (isset($plugin_collections[$property_name])) {
        // If external code updates the settings, pass it along to the plugin.         $plugin_collections[$property_name]->setConfiguration($value);
      }
    }

    $this->{$property_name} = $value;

    return $this;
  }

  


  /** * Tests updating a filter format during import. */
  protected function doFilterFormatUpdate() {
    // Create a test filter format with a known label.     $name = 'filter.format.plain_text';

    /** @var \Drupal\filter\Entity\FilterFormat $entity */
    $entity = FilterFormat::load('plain_text');
    $plugin_collection = $entity->getPluginCollections()['filters'];

    $filters = $entity->get('filters');
    $this->assertSame(72, $filters['filter_url']['settings']['filter_url_length']);

    $filters['filter_url']['settings']['filter_url_length'] = 100;
    $entity->set('filters', $filters);
    $entity->save();
    $this->assertSame($filters$entity->get('filters'));
    $this->assertSame($filters$plugin_collection->getConfiguration());

    $filters['filter_url']['settings']['filter_url_length'] = -100;
    

  protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {
    $values = $form_state->getValues();

    if ($this->entity instanceof EntityWithPluginCollectionInterface) {
      // Do not manually update values represented by plugin collections.       $values = array_diff_key($values$this->entity->getPluginCollections());
    }

    // @todo This relies on a method that only exists for config and content     // entities, in a different way. Consider moving this logic to a config     // entity specific implementation.     foreach ($values as $key => $value) {
      $entity->set($key$value);
    }
  }

  /** * {@inheritdoc} */
$this->messenger()->addStatus($this->t('Your settings have been saved.'));
  }

  /** * {@inheritdoc} */
  protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {
    $form_values = $form_state->getValues();

    if ($this->entity instanceof EntityWithPluginCollectionInterface) {
      // Do not manually update values represented by plugin collections.       $form_values = array_diff_key($form_values$this->entity->getPluginCollections());
    }

    // Collect data for 'regular' fields.     foreach ($form['#fields'] as $field_name) {
      $values = $form_values['fields'][$field_name];

      if ($values['region'] == 'hidden') {
        $entity->removeComponent($field_name);
      }
      else {
        $options = $entity->getComponent($field_name);

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