Skip to content

Commit

Permalink
[FC] Core should know from module metadata if it supports categorizat…
Browse files Browse the repository at this point in the history
…ion and for which entities it supports. refs #411.

This implements a key in the `capabilities` module as described in the ticket (using American spelling - categorizable). the value for the key is an array of FQ Entity names.
  • Loading branch information
craigh committed Jul 9, 2015
1 parent 6047050 commit c7c284b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
19 changes: 18 additions & 1 deletion src/lib/legacy/util/HtmlUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,24 @@ public static function getSelector_ModuleTables($modname, $name, $selectedValue
}

// Doctrine 2 entities (Core 1.3.0++)
// Core-2.0 spec
$module = ModUtil::getModule($modname);
if ((null !== $module) && !class_exists($module->getVersionClass())) {
// this check just confirming a Core-2.0 spec bundle - remove in 2.0.0
$capabilities = $module->getMetaData()->getCapabilities();
if (isset($capabilities['categorizable'])) {
$data = array();
foreach ($capabilities['categorizable'] as $fullyQualifiedEntityName) {
$nameParts = explode('\\', $fullyQualifiedEntityName);
$entityName = array_pop($nameParts);
$data[$entityName] = $entityName;
}
$selectedValue = (count($data) == 1) ? $entityName : $defaultValue;
return self::getSelector_Generic($name, $data, $selectedValue, $defaultValue, $defaultText, null, null, $submit, $disabled, $multipleSize);
}
}

// (Core-1.3 spec)
$modinfo = ModUtil::getInfo(ModUtil::getIdFromName($modname));
$modpath = ($modinfo['type'] == ModUtil::TYPE_SYSTEM) ? 'system' : 'modules';
$osdir = DataUtil::formatForOS($modinfo['directory']);
Expand All @@ -490,7 +508,6 @@ public static function getSelector_ModuleTables($modname, $name, $selectedValue
}
}

$module = ModUtil::getModule($modname);
$data = array();
foreach ($entities as $entity) {
$possibleClassNames = array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,23 @@ public function editregistryAction(Request $request)
}

$registries = $this->entityManager->getRepository('ZikulaCategoriesModule:CategoryRegistryEntity')->findBy(array(), array('modname' => 'ASC', 'property' => 'ASC'));
$modules = $this->entityManager->getRepository('Zikula\Core\Doctrine\Entity\ExtensionEntity')->findBy(array('state' => 3), array('displayname' => 'ASC'));
$moduleOptions = array();
foreach ($modules as $module) {
$bundle = \ModUtil::getModule($module['name']);
if ((null !== $bundle) && !class_exists($bundle->getVersionClass())) {
// this check just confirming a Core-2.0 spec bundle - remove in 2.0.0
// then instead of getting MetaData, could just do ModUtil::getCapabilitiesOf($module['name'])
$capabilities = $bundle->getMetaData()->getCapabilities();
if (!isset($capabilities['categorizable'])) {
continue; // skip this module if not categorizable
}
}
$moduleOptions[$module['name']] = $module['displayname'];
}

$this->view->assign('objectArray', $registries)
->assign('moduleOptions', $moduleOptions)
->assign('newobj', $obj)
->assign('root_id', $root_id)
->assign('id', $id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
{if $obj.id eq $id}
<input id="category_registry_id" name="category_registry[id]" value="{$obj.id}" type="hidden" />
<td>
{selector_module name='category_registry[modname]' selectedValue=$obj.modname defaultValue='' defaultText=$chooseModule submit='1'}
<select name="category_registry[modname]" id="category_registry__id__" onchange="this.form.submit();">
{foreach from=$moduleOptions key='value' item='text' }<option value="{$value}"{if $value eq $obj.modname} selected="selected"{/if}>{$text}</option>{/foreach}
</select>
</td>
<td>
{if $obj.modname}{selector_module_tables modname=$obj.modname name='category_registry[entityname]' selectedValue=$obj.entityname defaultValue='' defaultText=$chooseEntity}
Expand Down Expand Up @@ -57,7 +59,11 @@
{if $id eq 0}
<tr>
<td>
<span class="required"></span>{selector_module name="category_registry[modname]" defaultValue="0" defaultText=$chooseModule selectedValue=$newobj.modname|default:'' submit="1"}
<span class="required"></span>
<select name="category_registry[modname]" id="category_registry__id__" onchange="this.form.submit();">
<option value="0"{if empty($newobj.modname)} selected="selected"{/if}>{$chooseModule}</option>
{foreach from=$moduleOptions key='value' item='text' }<option value="{$value}"{if $value eq $newobj.modname|default:''} selected="selected"{/if}>{$text}</option>{/foreach}
</select>
</td>
<td>
{if !empty($newobj.modname)}
Expand Down

0 comments on commit c7c284b

Please sign in to comment.