calculatePluginDependencies example


  public function calculateDependencies() {
    // All dependencies should be recalculated on every save apart from enforced     // dependencies. This ensures stale dependencies are never saved.     $this->dependencies = array_intersect_key($this->dependencies, ['enforced' => '']);
    if ($this instanceof EntityWithPluginCollectionInterface) {
      // Configuration entities need to depend on the providers of any plugins       // that they store the configuration for.       foreach ($this->getPluginCollections() as $plugin_collection) {
        foreach ($plugin_collection as $instance) {
          $this->calculatePluginDependencies($instance);
        }
      }
    }
    if ($this instanceof ThirdPartySettingsInterface) {
      // Configuration entities need to depend on the providers of any third       // parties that they store the configuration for.       foreach ($this->getThirdPartyProviders() as $provider) {
        $this->addDependency('module', $provider);
      }
    }
    return $this;
  }
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;
  }

  /** * {@inheritdoc} */
  public function preSave(EntityStorageInterface $storage) {
    parent::preSave($storage);

    


  /** * {@inheritdoc} */
  protected function calculatePluginDependencies(PluginInspectionInterface $instance) {
    // Only add dependencies for plugins that are actually configured. This is     // necessary because the filter plugin collection will return all available     // filter plugins.     // @see \Drupal\filter\FilterPluginCollection::getConfiguration()     if (isset($this->filters[$instance->getPluginId()])) {
      parent::calculatePluginDependencies($instance);
    }
  }

}
// Add the module providing the configured field storage as a dependency.     if (($field_storage_definition = $this->getFieldStorageDefinition()) && $field_storage_definition instanceof EntityInterface) {
      $this->dependencies['config'][] = $field_storage_definition->getConfigDependencyName();
    }
    if (!empty($this->options['type'])) {
      // Add the module providing the formatter.       $this->dependencies['module'][] = $this->formatterPluginManager->getDefinition($this->options['type'])['provider'];

      // Add the formatter's dependencies.       if (($formatter = $this->getFormatterInstance()) && $formatter instanceof DependentPluginInterface) {
        $this->calculatePluginDependencies($formatter);
      }
    }

    return $this->dependencies;
  }

  /** * {@inheritdoc} */
  public function getCacheMaxAge() {
    return Cache::PERMANENT;
  }

  public function calculateDependencies() {
    parent::calculateDependencies();

    // This can be called during uninstallation, so check for a valid ID first.     if ($this->getLayoutId()) {
      $this->calculatePluginDependencies($this->getLayout());
    }
    return $this;
  }

  /** * Implements \Drupal\field_layout\Display\EntityDisplayWithLayoutInterface::getDefaultRegion(). */
  public function getDefaultRegion() {
    return $this->getLayoutDefinition($this->getLayoutId())->getDefaultRegion();
  }

}
$module_handler->moduleExists('test_module1')->willReturn(TRUE);
    $module_handler->moduleExists('test_theme1')->willReturn(FALSE);
    $test_class->setModuleHandler($module_handler->reveal());

    $theme_handler = $this->prophesize(ThemeHandlerInterface::class);
    $theme_handler->themeExists('test_module1')->willReturn(FALSE);
    $theme_handler->themeExists('test_theme1')->willReturn(TRUE);
    $test_class->setThemeHandler($theme_handler->reveal());

    $plugin->getPluginDefinition()->willReturn($definition);

    $test_class->calculatePluginDependencies($plugin->reveal());
    $this->assertEquals($expected$test_class->getDependencies());
  }

  /** * Provides test data for plugin dependencies. */
  public static function providerTestPluginDependencies() {
    $prophet = new Prophet();
    $data = [];

    $plugin = $prophet->prophesize(PluginInspectionInterface::class);

    
$target_entity_type = $this->entityTypeManager()->getDefinition($this->getTargetEntityTypeId());
    return new TranslatableMarkup('@bundle @label', ['@bundle' => $bundle_label, '@label' => $target_entity_type->getPluralLabel()]);
  }

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

    foreach ($this->getSections() as $section) {
      $this->calculatePluginDependencies($section->getLayout());
      foreach ($section->getComponents() as $component) {
        $this->calculatePluginDependencies($component->getPlugin());
      }
    }

    return $this;
  }

  /** * {@inheritdoc} */
  
Home | Imprint | This part of the site doesn't use cookies.