I used Drupal 8 and written a module. in my form page I called.
\Drupal::service('library.discovery')->clearCachedDefinitions(); $cache = \Drupal::cache('discovery'); $cache->delete('block_plugins'); It's worked, but I always see the warning.
\Drupal calls should be avoided in classes, use | | dependency injection instead
I have the similar with File::load(), too. I used:
use Drupal\file\Entity\file; class BXBlock extends BlockBase { public function build() { ... $file = File::load($value); ... } } Anybody can help me, please? Thanks so much.