getOriginalMode example

/** @var \Drupal\Core\Field\WidgetPluginManager $field_widget_plugin_manager */
      $field_widget_plugin_manager = \Drupal::service('plugin.manager.field.widget');

      // Use the widget currently configured for the 'default' form mode, or       // fallback to the default widget for the field type.       if (($configuration = $entity_form_display->getComponent($definition->getName())) && isset($configuration['type'])) {
        // Get the plugin instance manually to ensure an up-to-date field         // definition is used.         // @see \Drupal\Core\Entity\Entity\EntityFormDisplay::getRenderer         $widget = $field_widget_plugin_manager->getInstance([
          'field_definition' => $definition,
          'form_mode' => $entity_form_display->getOriginalMode(),
          'prepare' => FALSE,
          'configuration' => $configuration,
        ]);
      }
      else {
        $widget = $field_widget_plugin_manager->getInstance(['field_definition' => $definition]);
      }

      $form_state->set('default_value_widget', $widget);
    }

    
$reflection->setValue($mock, 'test');
    $this->assertEquals('test', $mock->getMode());
  }

  /** * @covers ::getOriginalMode */
  public function testGetOriginalMode() {
    $mock = $this->getMockForAbstractClass('\Drupal\Core\Entity\EntityDisplayBase', [], '', FALSE);
    $reflection = new \ReflectionProperty($mock, 'originalMode');
    $reflection->setValue($mock, 'test');
    $this->assertEquals('test', $mock->getOriginalMode());
  }

  /** * @covers ::getTargetBundle */
  public function testGetTargetBundle() {
    $mock = $this->getMockForAbstractClass('\Drupal\Core\Entity\EntityDisplayBase', [], '', FALSE);
    $reflection = new \ReflectionProperty($mock, 'bundle');
    $reflection->setValue($mock, 'test');
    $this->assertEquals('test', $mock->getTargetBundle());
  }

  
protected function contextRepository() {
    return \Drupal::service('context.repository');
  }

  /** * Indicates if this display is using the '_custom' view mode. * * @return bool * TRUE if this display is using the '_custom' view mode, FALSE otherwise. */
  protected function isCustomMode() {
    return $this->getOriginalMode() === static::CUSTOM_MODE;
  }

  /** * {@inheritdoc} */
  public function buildMultiple(array $entities) {
    $build_list = parent::buildMultiple($entities);

    // Layout Builder can not be enabled for the '_custom' view mode that is     // used for on-the-fly rendering of fields in isolation from the entity.     if ($this->isCustomMode()) {
      
Home | Imprint | This part of the site doesn't use cookies.