View source
<?php
function farm_ui_farm_ui_entity_view_groups() {
$groups = array(
'assets' => array(
'title' => t('Assets'),
'weight' => 100,
),
'logs' => array(
'title' => t('Logs by type'),
'weight' => 110,
),
'logs_special' => array(
'title' => t('Logs with special purpose'),
'weight' => 111,
'collapse' => TRUE,
),
'other' => array(
'weight' => 200,
),
);
return $groups;
}
function farm_ui_farm_ui_entity_views($entity_type, $entity_bundle, $entity) {
$views = array();
$ui_info = farm_ui_entities();
if ($entity_type == 'taxonomy_term' && $entity_bundle == 'farm_areas') {
$types = array(
'farm_asset',
'log',
);
foreach ($types as $type) {
if (!empty($ui_info[$type])) {
foreach ($ui_info[$type] as $bundle => $info) {
if (empty($info['view'])) {
continue;
}
if ($type == 'log' && (empty($info['areas']) || $info['areas'] !== TRUE)) {
continue;
}
$group = 'other';
switch ($type) {
case 'farm_asset':
$group = 'assets';
break;
case 'log':
$group = 'logs';
break;
}
$area_argument_position = farm_ui_views_area_argument_position($type, $bundle);
$view = array(
'name' => $info['view'],
'arg' => $area_argument_position,
'group' => $group,
);
if (!empty($info['weight'])) {
$view['weight'] = $info['weight'];
}
$views[] = $view;
}
}
}
}
elseif ($entity_type == 'taxonomy_term') {
if (!empty($ui_info[$entity_type][$entity_bundle]['farm_asset'])) {
$asset_type = $ui_info[$entity_type][$entity_bundle]['farm_asset'];
if (!empty($ui_info['farm_asset'][$asset_type]['view'])) {
$asset_view = $ui_info['farm_asset'][$asset_type]['view'];
if (!empty($ui_info[$entity_type][$entity_bundle]['asset_view_arg'])) {
$arg = $ui_info[$entity_type][$entity_bundle]['asset_view_arg'];
$views[] = array(
'name' => $asset_view,
'arg' => $arg,
'group' => 'assets',
'always' => TRUE,
);
}
}
}
}
return $views;
}
function farm_ui_farm_ui_actions() {
$actions = array(
'area' => array(
'title' => t('Add area'),
'href' => 'admin/structure/taxonomy/farm_areas/add',
'paths' => array(
'farm',
),
'weight' => -10,
),
'asset' => array(
'title' => t('Add asset'),
'href' => 'farm/asset/add',
'paths' => array(
'farm',
'farm/assets',
'farm/assets/all',
),
),
'log' => array(
'title' => t('Add log'),
'href' => 'log/add',
'paths' => array(
'farm',
'farm/logs',
'farm/logs/all',
),
'weight' => 1,
),
'plan' => array(
'title' => t('Add plan'),
'href' => 'farm/plan/add',
'paths' => array(
'farm/plans',
),
'weight' => 1,
),
'user' => array(
'title' => t('Add person'),
'href' => 'admin/people/create',
'views' => array(
'farm_people',
),
),
);
$ui_info = farm_ui_entities();
foreach ($ui_info as $entity_type => $bundles) {
foreach ($bundles as $bundle => $info) {
if (!empty($info['label']) && !empty($info['view'])) {
switch ($entity_type) {
case 'farm_asset':
$path = 'farm/asset/add/' . $bundle;
break;
case 'farm_plan':
$path = 'farm/plan/add/' . $bundle;
break;
case 'log':
$path = 'log/add/' . $bundle;
break;
case 'taxonomy_term':
$path = 'admin/structure/taxonomy/' . $bundle . '/add';
break;
}
$actions[$bundle] = array(
'title' => t('Add ' . strtolower($info['label'])),
'href' => $path,
'views' => array(
$info['view'],
),
);
}
if (!empty($info['weight'])) {
$actions[$bundle]['weight'] = $info['weight'];
}
if ($entity_type == 'log') {
if (empty($info['farm_asset']) || $info['farm_asset'] == 'all') {
$actions[$bundle]['assets'] = array(
'all',
);
}
elseif ($info['farm_asset'] != 'none') {
$actions[$bundle]['assets'] = array(
$info['farm_asset'],
);
}
if (!empty($info['areas']) && $info['areas'] === TRUE) {
$actions[$bundle]['paths'] = array(
'taxonomy/term/%',
);
}
}
}
}
return $actions;
}