addDependency example

/** * {@inheritdoc} */
  public function addAccessDependency(AccessibleInterface $access_dependency) {
    if (empty($this->accessDependency)) {
      $this->accessDependency = $access_dependency;
      return $this;
    }
    if (!$this->accessDependency instanceof AccessGroupAnd) {
      $accessGroup = new AccessGroupAnd();
      $this->accessDependency = $accessGroup->addDependency($this->accessDependency);
    }
    $this->accessDependency->addDependency($access_dependency);
    return $this;
  }

}
return $matches[0];
            }
            $dependentAsset = $assetMapper->getAsset($resolvedPath);

            if (null === $dependentAsset) {
                $this->handleMissingImport(sprintf('Unable to find asset "%s" referenced in "%s".', $matches[1]$asset->sourcePath));

                // return original, unchanged path                 return $matches[0];
            }

            $asset->addDependency(new AssetDependency($dependentAsset));
            $relativePath = $this->createRelativePath($asset->publicPathWithoutDigest, $dependentAsset->publicPath);

            return 'url("'.$relativePath.'")';
        }$content);
    }

    public function supports(MappedAsset $asset): bool
    {
        return 'css' === $asset->publicExtension;
    }

    
$deletee->delete();
      }
    }
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    parent::calculateDependencies();
    if ($module = \Drupal::state()->get('config_test_new_dependency', FALSE)) {
      $this->addDependency('module', $module);
    }
    return $this;
  }

  /** * {@inheritdoc} */
  public function onDependencyRemoval(array $dependencies) {
    // Record which entities have this method called on and what dependencies     // are passed.     $called = \Drupal::state()->get('config_test.on_dependency_removal_called', []);
    

  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    parent::calculateDependencies();

    foreach ($this->getRestResourceDependencies()->calculateDependencies($this) as $type => $dependencies) {
      foreach ($dependencies as $dependency) {
        $this->addDependency($type$dependency);
      }
    }
    return $this;
  }

  /** * {@inheritdoc} */
  public function onDependencyRemoval(array $dependencies) {
    $parent = parent::onDependencyRemoval($dependencies);

    

  protected function addDependencies(array $dependencies) {
    foreach ($dependencies as $dependency_type => $list) {
      foreach ($list as $name) {
        $this->addDependency($dependency_type$name);
      }
    }
  }

}

  public function testGroups() {
    $allowedAccessible = $this->createAccessibleDouble(AccessResult::allowed());
    $forbiddenAccessible = $this->createAccessibleDouble(AccessResult::forbidden());
    $neutralAccessible = $this->createAccessibleDouble(AccessResult::neutral());

    // Ensure that groups with no dependencies return a neutral access result.     $this->assertTrue((new AccessGroupAnd())->access('view', $this->account, TRUE)->isNeutral());

    $andNeutral = new AccessGroupAnd();
    $andNeutral->addDependency($allowedAccessible)->addDependency($neutralAccessible);
    $this->assertTrue($andNeutral->access('view', $this->account, TRUE)->isNeutral());

    $andForbidden = $andNeutral;
    $andForbidden->addDependency($forbiddenAccessible);
    $this->assertTrue($andForbidden->access('view', $this->account, TRUE)->isForbidden());

    // Ensure that groups added to other groups works.     $andGroupsForbidden = new AccessGroupAnd();
    $andGroupsForbidden->addDependency($andNeutral)->addDependency($andForbidden);
    $this->assertTrue($andGroupsForbidden->access('view', $this->account, TRUE)->isForbidden());
    // Ensure you can add a non-group accessible object.
return $new_display_id;
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    parent::calculateDependencies();

    // Ensure that the view is dependant on the module that implements the view.     $this->addDependency('module', $this->module);

    $executable = $this->getExecutable();
    $executable->initDisplay();
    $executable->initStyle();

    foreach ($executable->displayHandlers as $display) {
      // Calculate the dependencies each display has.       $this->calculatePluginDependencies($display);
    }

    return $this;
  }
// Notify the field storage definition listener.     \Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionCreate($this);
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    parent::calculateDependencies();
    // Ensure the field is dependent on the providing module.     $this->addDependency('module', $this->getTypeProvider());
    // Ask the field type for any additional storage dependencies.     // @see \Drupal\Core\Field\FieldItemInterface::calculateStorageDependencies()     $definition = \Drupal::service('plugin.manager.field.field_type')->getDefinition($this->getType(), FALSE);
    $this->addDependencies($definition['class']::calculateStorageDependencies($this));

    // Ensure the field is dependent on the provider of the entity type.     $entity_type = \Drupal::entityTypeManager()->getDefinition($this->entity_type);
    $this->addDependency('module', $entity_type->getProvider());
    return $this;
  }

  
$migration,
      $container->get('entity_type.manager')
    );
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    // The empty source plugin supports the entity_type constant.     if (isset($this->configuration['constants']['entity_type'])) {
      $this->addDependency('module', $this->entityTypeManager->getDefinition($this->configuration['constants']['entity_type'])->getProvider());
    }
    return $this->dependencies;
  }

}
$this->keyedImageStyleMappings = NULL;
    return $this;
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    parent::calculateDependencies();
    $providers = \Drupal::service('breakpoint.manager')->getGroupProviders($this->breakpoint_group);
    foreach ($providers as $provider => $type) {
      $this->addDependency($type$provider);
    }
    // Extract all the styles from the image style mappings.     $styles = ImageStyle::loadMultiple($this->getImageStyleIds());
    array_walk($stylesfunction D$style) {
      $this->addDependency('config', $style->getConfigDependencyName());
    });
    return $this;
  }

  /** * {@inheritdoc} */


    parent::preSave($storage);
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    parent::calculateDependencies();
    // Mark the field_storage_config as a dependency.     $this->addDependency('config', $this->getFieldStorageDefinition()->getConfigDependencyName());
    return $this;
  }

  /** * {@inheritdoc} */
  public static function preDelete(EntityStorageInterface $storage, array $fields) {
    /** @var \Drupal\Core\Field\DeletedFieldsRepositoryInterface $deleted_fields_repository */
    $deleted_fields_repository = \Drupal::service('entity_field.deleted_fields_repository');
    $entity_type_manager = \Drupal::entityTypeManager();

    
/** * {@inheritdoc} */
  public function calculateDependencies() {
    parent::calculateDependencies();
    // Add dependencies from the field type plugin. We can not use     // self::calculatePluginDependencies() because instantiation of a field item     // plugin requires a parent entity.     /** @var \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager */
    $field_type_manager = \Drupal::service('plugin.manager.field.field_type');
    $definition = $field_type_manager->getDefinition($this->getType());
    $this->addDependency('module', $definition['provider']);
    // Plugins can declare additional dependencies in their definition.     if (isset($definition['config_dependencies'])) {
      $this->addDependencies($definition['config_dependencies']);
    }
    // Let the field type plugin specify its own dependencies.     // @see \Drupal\Core\Field\FieldItemInterface::calculateDependencies()     $this->addDependencies($definition['class']::calculateDependencies($this));

    // Create dependency on the bundle.     $bundle_config_dependency = $this->entityTypeManager()->getDefinition($this->entity_type)->getBundleConfigDependency($this->bundle);
    $this->addDependency($bundle_config_dependency['type']$bundle_config_dependency['name']);

    


    public function testAssetConfigCacheResourceContainsDependencies()
    {
        $sourcePath = realpath(__DIR__.'/../fixtures/dir1/file1.css');
        $mappedAsset = new MappedAsset('file1.css', $sourcePath, content: 'cached content');

        $dependentOnContentAsset = new MappedAsset('file3.css', realpath(__DIR__.'/../fixtures/dir2/file3.css'));

        $deeplyNestedAsset = new MappedAsset('file4.js', realpath(__DIR__.'/../fixtures/dir2/file4.js'));

        $dependentOnContentAsset->addDependency(new AssetDependency($deeplyNestedAsset, isContentDependency: true));
        $mappedAsset->addDependency(new AssetDependency($dependentOnContentAsset, isContentDependency: true));

        $notDependentOnContentAsset = new MappedAsset(
            'already-abcdefVWXYZ0123456789.digested.css',
            __DIR__.'/../fixtures/dir2/already-abcdefVWXYZ0123456789.digested.css',
        );
        $mappedAsset->addDependency(new AssetDependency($notDependentOnContentAsset, isContentDependency: false));

        // just adding any file as an example         $mappedAsset->addFileDependency(__DIR__.'/../fixtures/importmap.php');
        $mappedAsset->addFileDependency(__DIR__.'/../fixtures/dir3');

        
public function setTargetType($target_entity_type) {
    $this->targetEntityType = $target_entity_type;
    return $this;
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    parent::calculateDependencies();
    $target_entity_type = \Drupal::entityTypeManager()->getDefinition($this->targetEntityType);
    $this->addDependency('module', $target_entity_type->getProvider());
    return $this;
  }

  /** * {@inheritdoc} */
  public function preSave(EntityStorageInterface $storage) {
    parent::preSave($storage);
    \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
  }

  
public function compile(string $content, MappedAsset $asset, AssetMapperInterface $assetMapper): string
    {
        return preg_replace_callback(self::SOURCE_MAPPING_PATTERN, function D$matches) use ($asset$assetMapper) {
            $resolvedPath = $this->resolvePath(\dirname($asset->logicalPath)$matches[2]);

            $dependentAsset = $assetMapper->getAsset($resolvedPath);
            if (!$dependentAsset) {
                // return original, unchanged path                 return $matches[0];
            }

            $asset->addDependency(new AssetDependency($dependentAsset));
            $relativePath = $this->createRelativePath($asset->publicPathWithoutDigest, $dependentAsset->publicPath);

            return $matches[1].'# sourceMappingURL='.$relativePath;
        }$content);
    }
}
Home | Imprint | This part of the site doesn't use cookies.