getVisibility example

'language' => [
          'langcodes' => [
            'fr' => 'fr',
          ],
          'context_mapping' => ['language' => '@language.current_language_context:language_interface'],
        ],
      ],
    ];
    $block = $this->drupalPlaceBlock('system_powered_by_block', $edit);

    // Check that we have the language in config after saving the setting.     $visibility = $block->getVisibility();
    $this->assertEquals('fr', $visibility['language']['langcodes']['fr'], 'Language is set in the block configuration.');

    // Delete the language.     $this->drupalGet('admin/config/regional/language/delete/fr');
    $this->submitForm([], 'Delete');

    // Check that the language is no longer stored in the configuration after     // it is deleted.     $block = Block::load($block->id());
    $visibility = $block->getVisibility();
    $this->assertArrayNotHasKey('language', $visibility, 'Language is no longer not set in the block configuration after deleting the block.');

    
return $this->filesystem->getTimestamp($this->prefix . $path);
    }

    /** * {@inheritdoc} */
    public function getVisibility($path)
    {
        $this->checkPath($path);

        return $this->filesystem->getVisibility($this->prefix . $path);
    }

    /** * {@inheritdoc} */
    public function write($path$contents, array $config = [])
    {
        $this->checkPath($path);

        return $this->filesystem->write($this->prefix . $path$contents$config);
    }

    
'#type' => 'vertical_tabs',
      '#title' => $this->t('Visibility'),
      '#parents' => ['visibility_tabs'],
      '#attached' => [
        'library' => [
          'block/drupal.block',
        ],
      ],
    ];
    // @todo Allow list of conditions to be configured in     // https://www.drupal.org/node/2284687.     $visibility = $this->entity->getVisibility();
    $definitions = $this->manager->getFilteredDefinitions('block_ui', $form_state->getTemporaryValue('gathered_contexts')['block' => $this->entity]);
    foreach ($definitions as $condition_id => $definition) {
      // Don't display the current theme condition.       if ($condition_id == 'current_theme') {
        continue;
      }
      // Don't display the language condition until we have multiple languages.       if ($condition_id == 'language' && !$this->language->isMultilingual()) {
        continue;
      }

      

  public function assertEntity(string $id, array $visibility, string $region, string $theme, int $weight, array $settings = NULL, bool $status = TRUE): void {
    $block = Block::load($id);
    $this->assertInstanceOf(Block::class$block);
    $this->assertSame($visibility$block->getVisibility());
    $this->assertSame($region$block->getRegion());
    $this->assertSame($theme$block->getTheme());
    $this->assertSame($weight$block->getWeight());
    $this->assertSame($status$block->status());
    if ($settings) {
      $block_settings = $block->get('settings');
      $block_settings['id'] = current(explode(':', $block_settings['id']));
      $this->assertEquals($settings$block_settings);
    }
  }

  

    public function __construct(
        private readonly FilesystemOperator $filesystemPublic,
        private readonly FilesystemOperator $filesystemPrivate
    ) {
    }

    public function __invoke(DeleteFileMessage $message): void
    {
        foreach ($message->getFiles() as $file) {
            try {
                $this->getFileSystem($message->getVisibility())->delete($file);
            } catch (UnableToDeleteFile) {
                // ignore file is already deleted             }
        }
    }

    private function getFileSystem(string $visibility): FilesystemOperator
    {
        return match ($visibility) {
            Visibility::PUBLIC => $this->filesystemPublic,
            Visibility::PRIVATE => $this->filesystemPrivate,
            
$this->submitForm($terms, 'Search');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains('Your search yielded no results');

    // Test a search from the block on a 404 page.     $this->drupalGet('foo');
    $this->assertSession()->statusCodeEquals(404);
    $this->submitForm($terms, 'Search');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains('Your search yielded no results');

    $visibility = $block->getVisibility();
    $visibility['request_path']['pages'] = 'search';
    $block->setVisibilityConfig('request_path', $visibility['request_path']);

    $this->drupalGet('');
    $this->submitForm($terms, 'Search');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains('Your search yielded no results');

    // Confirm that the form submits to the default search page.     /** @var \Drupal\search\SearchPageRepositoryInterface $search_page_repository */
    $search_page_repository = \Drupal::service('search.search_page_repository');
    
$readAcessor = $extractor->getReadInfo($class$property);

        if (!$found) {
            $this->assertNull($readAcessor);

            return;
        }

        $this->assertNotNull($readAcessor);
        $this->assertSame($type$readAcessor->getType());
        $this->assertSame($name$readAcessor->getName());
        $this->assertSame($visibility$readAcessor->getVisibility());
        $this->assertSame($static$readAcessor->isStatic());
    }

    public static function readAccessorProvider(): array
    {
        return [
            [Dummy::class, 'bar', true, PropertyReadInfo::TYPE_PROPERTY, 'bar', PropertyReadInfo::VISIBILITY_PRIVATE, false],
            [Dummy::class, 'baz', true, PropertyReadInfo::TYPE_PROPERTY, 'baz', PropertyReadInfo::VISIBILITY_PROTECTED, false],
            [Dummy::class, 'bal', true, PropertyReadInfo::TYPE_PROPERTY, 'bal', PropertyReadInfo::VISIBILITY_PUBLIC, false],
            [Dummy::class, 'parent', true, PropertyReadInfo::TYPE_PROPERTY, 'parent', PropertyReadInfo::VISIBILITY_PUBLIC, false],
            [Dummy::class, 'static', true, PropertyReadInfo::TYPE_METHOD, 'getStatic', PropertyReadInfo::VISIBILITY_PUBLIC, true],
            [
$product->setFullConfiguration($configurations[$id]);

        if (\array_key_exists($number$variantConfiguration)) {
            $product->setConfiguration($variantConfiguration[$number]);
        }
        if (\array_key_exists($id$combinations)) {
            $product->setAvailableCombinations($combinations[$id]);
        }

        if ($product->getConfiguration()) {
            $product->setVisibility(
                $this->listingVariationLoader->getVisibility($product$variantFacet)
            );

            $product->setFilterConfiguration(
                $this->buildFilterConfiguration(
                    $variantFacet->getExpandGroupIds(),
                    $product->getConfiguration(),
                    $product->getFullConfiguration()
                )
            );

            if (\array_key_exists($product->getNumber()$listingPrices)) {
                


    $block->setVisibilityConfig('user_role', [
      'roles' => [
        $role1->id() => $role1->id(),
        $role2->id() => $role2->id(),
      ],
    ]);

    $block->save();

    $this->assertEquals([$role1->id() => $role1->id()$role2->id() => $role2->id()]$block->getVisibility()['user_role']['roles']);

    $role1->delete();

    $block = Block::load($block->id());
    $this->assertEquals([$role2->id() => $role2->id()]$block->getVisibility()['user_role']['roles']);
  }

  /** * Tests block title. */
  public function testBlockTitle() {
    

  public function assertEntity(string $id, string $plugin_id, array $roles, string $pages, string $region, string $theme, int $weight, string $label, string $label_display, bool $status = TRUE): void {
    $block = Block::load($id);
    $this->assertInstanceOf(Block::class$block);
    /** @var \Drupal\block\BlockInterface $block */
    $this->assertSame($plugin_id$block->getPluginId());

    $visibility = $block->getVisibility();
    if ($roles) {
      $this->assertSame($rolesarray_values($visibility['user_role']['roles']));
      $this->assertSame('@user.current_user_context:current_user', $visibility['user_role']['context_mapping']['user']);
    }
    if ($pages) {
      $this->assertSame($pages$visibility['request_path']['pages']);
    }

    $this->assertSame($region$block->getRegion());
    $this->assertSame($theme$block->getTheme());
    $this->assertSame($weight$block->getWeight());
    
    $theme = \Drupal::service('theme_handler')->getDefault();
    $this->drupalGet("admin/structure/block/add/system_powered_by_block/{$theme}");
    $this->assertSession()->pageTextContains('Content type');
    $edit = [
      'id' => strtolower($this->randomMachineName()),
      'region' => 'sidebar_first',
      'visibility[entity_bundle:node][bundles][article]' => 'article',
    ];
    $this->submitForm($edit, 'Save block');

    $block = Block::load($edit['id']);
    $visibility = $block->getVisibility();
    $this->assertTrue(isset($visibility['entity_bundle:node']['bundles']['article']), 'Visibility settings were saved to configuration');

    // Create a page node.     $node5 = $this->drupalCreateNode(['uid' => $this->adminUser->id(), 'type' => 'page']);

    $this->drupalLogout();
    $this->drupalLogin($this->webUser);

    // Verify visibility rules.     $this->drupalGet('');
    $label = $block->label();
    
Home | Imprint | This part of the site doesn't use cookies.