mirror of
https://github.com/farmOS/farmOS.git
synced 2024-02-23 11:37:38 +01:00
Add view of inventory adjustments in an inventory tab on asset pages.
This commit is contained in:
parent
19e2c845c1
commit
f534299d38
4 changed files with 1736 additions and 0 deletions
1669
modules/core/ui/views/config/optional/views.view.farm_inventory.yml
Normal file
1669
modules/core/ui/views/config/optional/views.view.farm_inventory.yml
Normal file
File diff suppressed because it is too large
Load diff
|
@ -13,6 +13,11 @@ services:
|
|||
arguments: [ '@entity_type.manager', '@asset.location' ]
|
||||
tags:
|
||||
- { name: access_check, applies_to: _asset_children_access }
|
||||
farm_ui_views.asset_inventory_access:
|
||||
class: Drupal\farm_ui_views\Access\FarmInventoryAssetViewsAccessCheck
|
||||
arguments: [ '@entity_type.manager' ]
|
||||
tags:
|
||||
- { name: access_check, applies_to: _asset_inventory_access }
|
||||
farm_ui_views.location_assets_access:
|
||||
class: Drupal\farm_ui_views\Access\FarmLocationAssetViewsAccessCheck
|
||||
arguments: [ '@entity_type.manager', '@asset.location' ]
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\farm_ui_views\Access;
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Routing\Access\AccessInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
|
||||
/**
|
||||
* Checks access for displaying Views of inventory quantities for an asset.
|
||||
*/
|
||||
class FarmInventoryAssetViewsAccessCheck implements AccessInterface {
|
||||
|
||||
/**
|
||||
* The asset storage.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $assetStorage;
|
||||
|
||||
/**
|
||||
* FarmInventoryAssetViewsAccessCheck constructor.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager service.
|
||||
*/
|
||||
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
|
||||
$this->assetStorage = $entity_type_manager->getStorage('asset');
|
||||
}
|
||||
|
||||
/**
|
||||
* A custom access check.
|
||||
*
|
||||
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
|
||||
* The route match.
|
||||
*/
|
||||
public function access(RouteMatchInterface $route_match) {
|
||||
|
||||
// If there is no "asset" parameter, bail.
|
||||
$asset_id = $route_match->getParameter('asset');
|
||||
if (empty($asset_id)) {
|
||||
return AccessResult::allowed();
|
||||
}
|
||||
|
||||
// Allow access if the asset has an inventory.
|
||||
/** @var \Drupal\asset\Entity\AssetInterface $asset */
|
||||
$asset = $this->assetStorage->load($asset_id);
|
||||
$access = AccessResult::allowedIf($asset->hasField('inventory') && !$asset->get('inventory')->isEmpty());
|
||||
|
||||
// Invalidate the access result when the asset is changed.
|
||||
$access->addCacheTags($asset->getCacheTags());
|
||||
return $access;
|
||||
}
|
||||
|
||||
}
|
|
@ -33,6 +33,12 @@ class RouteSubscriber extends RouteSubscriberBase {
|
|||
if ($route = $collection->get('view.farm_asset.page_location')) {
|
||||
$route->setRequirement('_location_assets_access', 'Drupal\farm_ui_views\Access\FarmLocationAssetViewsAccessCheck::access');
|
||||
}
|
||||
|
||||
// Add our _inventory_asset_access requirement to
|
||||
// view.farm_inventory.page_asset.
|
||||
if ($route = $collection->get('view.farm_inventory.page_asset')) {
|
||||
$route->setRequirement('_asset_inventory_access', 'Drupal\farm_ui_views\Access\FarmInventoryAssetViewsAccessCheck::access');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue