getTarget example

    // favicon.     foreach (['logo' => 'logo.svg', 'favicon' => 'favicon.ico'] as $type => $default) {
      if (isset($form[$type]['settings'][$type . '_path'])) {
        $element = &$form[$type]['settings'][$type . '_path'];

        // If path is a public:// URI, display the path relative to the files         // directory; stream wrappers are not end-user friendly.         $original_path = $element['#default_value'];
        $friendly_path = NULL;

        if (StreamWrapperManager::getScheme($original_path) == 'public') {
          $friendly_path = StreamWrapperManager::getTarget($original_path);
          $element['#default_value'] = $friendly_path;
        }

        // Prepare local file path for description.         if ($original_path && isset($friendly_path)) {
          $local_file = strtr($original_path['public:/' => PublicStream::basePath()]);
        }
        elseif ($theme) {
          $local_file = $this->themeHandler->getTheme($theme)->getPath() . '/' . $default;
        }
        else {
          

function hook_file_download($uri) {
  // Check to see if this is a config download.   $scheme = StreamWrapperManager::getScheme($uri);
  $target = StreamWrapperManager::getTarget($uri);
  if ($scheme == 'temporary' && $target == 'config.tar.gz') {
    return [
      'Content-disposition' => 'attachment; filename="config.tar.gz"',
    ];
  }
}

/** * Alter the URL to a file. * * This hook is called from \Drupal\Core\File\FileUrlGenerator::generate(), * and is called fairly frequently (10+ times per page), depending on how many * files there are in a given page. * If CSS and JS aggregation are disabled, this can become very frequently * (50+ times per page) so performance is critical. * * This function should alter the URI, if it wants to rewrite the file URL. * * @param $uri * The URI to a file for which we need an external URL, or the path to a * shipped file. */
if (static::IGNORE_DOT_FILES === (static::IGNORE_DOT_FILES & $this->ignore)) {
            $notPaths[] = '#(^|/)\..+(/|$)#';
        }

        $minDepth = 0;
        $maxDepth = \PHP_INT_MAX;

        foreach ($this->depths as $comparator) {
            switch ($comparator->getOperator()) {
                case '>':
                    $minDepth = $comparator->getTarget() + 1;
                    break;
                case '>=':
                    $minDepth = $comparator->getTarget();
                    break;
                case '<':
                    $maxDepth = $comparator->getTarget() - 1;
                    break;
                case '<=':
                    $maxDepth = $comparator->getTarget();
                    break;
                default:
                    
$this->migration->method('id')->willReturn('foo');
  }

  /** * Tests different connection types. */
  public function testConnectionTypes() {
    $sql_base = new TestSqlBase([]$this->migration);

    // Verify that falling back to the default 'migrate' connection (defined in     // the base class) works.     $this->assertSame('default', $sql_base->getDatabase()->getTarget());
    $this->assertSame('migrate', $sql_base->getDatabase()->getKey());

    // Verify the fallback state key overrides the 'migrate' connection.     $target = 'test_fallback_target';
    $key = 'test_fallback_key';
    $config = ['target' => $target, 'key' => $key];
    $database_state_key = 'test_fallback_state';
    \Drupal::state()->set($database_state_key$config);
    \Drupal::state()->set('migrate.fallback_state_key', $database_state_key);
    // Create a test connection using the default database configuration.     Database::addConnectionInfo($key$target, Database::getConnectionInfo('default')['default']);
    
'filename' => $this->mediaService->getUrl($download->getFile()),
                'size' => $download->getSize(),
                'attributes' => $download->getAttributes(),
            ];
        }

        foreach ($product->getLinks() as $link) {
            $temp = [
                'id' => $link->getId(),
                'description' => $link->getDescription(),
                'link' => $link->getLink(),
                'target' => $link->getTarget(),
                'supplierSearch' => false,
                'attributes' => $link->getAttributes(),
            ];

            if (strpos($temp['link'], 'http') === false) {
                $temp['link'] = 'http://' . $link->getLink();
            }

            $data['sLinks'][] = $temp;
        }

        
/** * {@inheritdoc} */
  public function getDirectoryPath() {
    return static::basePath();
  }

  /** * {@inheritdoc} */
  public function getExternalUrl() {
    $path = str_replace('\\', '/', $this->getTarget());
    return static::baseUrl() . '/' . UrlHelper::encodePath($path);
  }

  /** * Finds and returns the base URL for public://. * * Defaults to the current site's base URL plus directory path. * * Note that this static method is used by \Drupal\system\Form\FileSystemForm * so you should alter that form or substitute a different form if you change * the class providing the stream_wrapper.public service. * * @return string * The external base URL for public:// */
return $this->origin;
    }

    /** * Matches a property path against the rule path. * * If the rule matches, the form mapped by the rule is returned. * Otherwise this method returns false. */
    public function match(string $propertyPath): ?FormInterface
    {
        return $propertyPath === $this->propertyPath ? $this->getTarget() : null;
    }

    /** * Matches a property path against a prefix of the rule path. */
    public function isPrefix(string $propertyPath): bool
    {
        $length = \strlen($propertyPath);
        $prefix = substr($this->propertyPath, 0, $length);
        $next = $this->propertyPath[$length] ?? null;

        
protected readonly Connection $connection,
    protected string $queryString,
    protected array $driverOptions = [],
    protected readonly bool $rowCountEnabled = FALSE,
  ) {
  }

  /** * {@inheritdoc} */
  public function getConnectionTarget(): string {
    return $this->connection->getTarget();
  }

  /** * {@inheritdoc} */
  public function execute($args = []$options = []) {
    if (isset($options['fetch'])) {
      if (is_string($options['fetch'])) {
        // Default to an object. Note: db fields will be added to the object         // before the constructor is run. If you need to assign fields after         // the constructor is run. See https://www.drupal.org/node/315092.
// Test the generateSampleValue() method.     $entity = EntityTest::create();
    $entity->file_test->generateSampleItems();
    $this->entityValidateAndSave($entity);
    // Verify that the sample file was stored in the correct directory.     $uri = $entity->file_test->entity->getFileUri();

    /** @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager */
    $stream_wrapper_manager = \Drupal::service('stream_wrapper_manager');

    $this->assertEquals($this->directory, dirname($stream_wrapper_manager::getTarget($uri)));

    // Make sure the computed files reflects updates to the file.     file_put_contents('public://example-3.txt', $this->randomMachineName());
    // Test unsaved file entity.     $file3 = File::create([
      'uri' => 'public://example-3.txt',
    ]);
    $display = \Drupal::service('entity_display.repository')
      ->getViewDisplay('entity_test', 'entity_test');
    $display->setComponent('file_test', [
      'label' => 'above',
      

  public function __construct(Connection $connection$options) {
    $this->uniqueIdentifier = uniqid('', TRUE);

    $this->connection = $connection;
    $this->connectionKey = $this->connection->getKey();
    $this->connectionTarget = $this->connection->getTarget();

    $this->queryOptions = $options;
  }

  /** * Implements the magic __sleep function to disconnect from the database. */
  public function __sleep() {
    $keys = get_object_vars($this);
    unset($keys['connection']);
    return array_keys($keys);
  }

  public function testCreateDeletePicture() {
    $this->drupalLogin($this->webUser);

    // Save a new picture.     $image = current($this->drupalGetTestFiles('image'));
    $file = $this->saveUserPicture($image);

    // Verify that the image is displayed on the user account page.     $this->drupalGet('user');
    $this->assertSession()->responseContains(StreamWrapperManager::getTarget($file->getFileUri()));

    // Delete the picture.     $edit = [];
    $this->drupalGet('user/' . $this->webUser->id() . '/edit');
    $this->submitForm($edit, 'Remove');
    $this->submitForm([], 'Save');

    // Call file_cron() to clean up the file. Make sure the timestamp     // of the file is older than the system.file.temporary_maximum_age     // configuration value. We use an UPDATE statement because using the API     // would set the timestamp.
RequirementExceptionStack $exceptionStack
    ): array {
        foreach ($package->getReplaces() as $replace) {
            $replaceConstraint = $replace->getConstraint();

            if ($replace->getPrettyConstraint() === 'self.version') {
                $replaceConstraint = new Constraint('==', $package->getVersion());
            }

            $pluginDependencies['require'] = $this->checkRequirement(
                $pluginDependencies['require'],
                $replace->getTarget(),
                $replaceConstraint,
                $exceptionStack
            );

            $pluginDependencies['conflict'] = $this->checkConflict(
                $pluginDependencies['conflict'],
                $this->pluginComposer->getPackage()->getName(),
                $replace->getTarget(),
                $replaceConstraint,
                $exceptionStack
            );
        }
$view->setDisplay();

    // Add 3 database connections for the different options that the method     // getConnection() supports.     $connection_info = Database::getConnectionInfo('default');
    Database::addConnectionInfo('default', 'replica', $connection_info['default']);
    Database::addConnectionInfo('corefake', 'default', $connection_info['default']);
    Database::addConnectionInfo('corefake', 'replica', $connection_info['default']);

    // Test the database connection with no special options set.     $this->assertSame('default', $view->getQuery()->getConnection()->getKey());
    $this->assertSame('default', $view->getQuery()->getConnection()->getTarget());

    // Test the database connection with the option 'replica' set to TRUE;     $view->getQuery()->options['replica'] = TRUE;
    $this->assertSame('default', $view->getQuery()->getConnection()->getKey());
    $this->assertSame('replica', $view->getQuery()->getConnection()->getTarget());

    // Test the database connection with the view 'base_database' set.     $view->getQuery()->options['replica'] = FALSE;
    $view->base_database = 'corefake';
    $this->assertSame('corefake', $view->getQuery()->getConnection()->getKey());
    $this->assertSame('default', $view->getQuery()->getConnection()->getTarget());

    
/** * {@inheritdoc} */
  public function getDirectoryPath() {
    return static::basePath();
  }

  /** * {@inheritdoc} */
  public function getExternalUrl() {
    $path = str_replace('\\', '/', $this->getTarget());
    return Url::fromRoute('system.private_file_download', ['filepath' => $path]['absolute' => TRUE, 'path_processing' => FALSE])->toString();
  }

  /** * Returns the base path for private://. * * Note that this static method is used by \Drupal\system\Form\FileSystemForm * so you should alter that form or substitute a different form if you change * the class providing the stream_wrapper.private service. * * @return string|null * The base path for private://. NULL means the private directory is not * set. */
/** * {@inheritdoc} */
  public function getTarget() {
    return $this->target;
  }

  /** * {@inheritdoc} */
  public function getValue() {
    if ($target = $this->getTarget()) {
      return $target->getValue();
    }
  }

  /** * {@inheritdoc} */
  public function setValue($value$notify = TRUE) {
    $this->target = $this->getTypedDataManager()->create($this->definition->getTargetDefinition()$value);
    // Notify the parent of any changes.     if ($notify && isset($this->parent)) {
      
Home | Imprint | This part of the site doesn't use cookies.