/** * {@inheritdoc} */ public function access(AccountInterface $account) { $bundles = $this->entityManager->getBundleInfo($this->getEntityType()); if ($this->options['hide_single_bundle'] && count($bundles) <= 1) { return FALSE; } return parent::access($account); }
/** * {@inheritdoc} */ public function access(AccountInterface $account) { $store_query = $this->entityManager->getStorage('commerce_store')->getQuery(); $store_count = $store_query->count()->execute(); if ($this->options['hide_single_store'] && $store_count <= 1) { return FALSE; } return parent::access($account); }
/** * @covers ::access */ public function testAccess() { $definition = ['entity_type' => 'test_entity', 'field_name' => 'title']; $handler = new Field([], 'field', $definition, $this->entityManager, $this->formatterPluginManager, $this->fieldTypePluginManager, $this->languageManager, $this->renderer); $handler->view = $this->executable; $handler->setViewsData($this->viewsData); $this->view->expects($this->atLeastOnce())->method('get')->with('base_table')->willReturn('test_entity_table'); $this->viewsData->expects($this->atLeastOnce())->method('get')->with('test_entity_table')->willReturn(['table' => ['entity type' => 'test_entity']]); $access_control_handler = $this->getMock('Drupal\\Core\\Entity\\EntityAccessControlHandlerInterface'); $this->entityManager->expects($this->atLeastOnce())->method('getAccessControlHandler')->with('test_entity')->willReturn($access_control_handler); $title_storage = $this->getBaseFieldStorage(); $this->entityManager->expects($this->atLeastOnce())->method('getFieldStorageDefinitions')->with('test_entity')->willReturn(['title' => $title_storage]); $account = $this->getMock('Drupal\\Core\\Session\\AccountInterface'); $access_control_handler->expects($this->atLeastOnce())->method('fieldAccess')->with('view', $this->anything(), $account, NULL, $this->anything())->willReturn(TRUE); $this->assertTrue($handler->access($account)); }