mirror of
https://github.com/joomla-extensions/weblinks.git
synced 2025-01-13 16:12:57 +00:00
Add Fields and Field Groups menu item during installation
This commit is contained in:
parent
c50f4c7dbe
commit
31d588492b
@ -9,6 +9,7 @@
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Extension\ExtensionHelper;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Filesystem\File;
|
||||
use Joomla\CMS\Filesystem\Folder;
|
||||
@ -92,27 +93,27 @@ class Com_WeblinksInstallerScript
|
||||
public function install($parent)
|
||||
{
|
||||
// Initialize a new category
|
||||
/** @type JTableCategory $category */
|
||||
/** @type JTableCategory $category */
|
||||
$category = Table::getInstance('Category');
|
||||
|
||||
// Check if the Uncategorised category exists before adding it
|
||||
if (!$category->load(array('extension' => 'com_weblinks', 'title' => 'Uncategorised')))
|
||||
{
|
||||
$category->extension = 'com_weblinks';
|
||||
$category->title = 'Uncategorised';
|
||||
$category->description = '';
|
||||
$category->published = 1;
|
||||
$category->access = 1;
|
||||
$category->params = '{"category_layout":"","image":""}';
|
||||
$category->metadata = '{"author":"","robots":""}';
|
||||
$category->metadesc = '';
|
||||
$category->metakey = '';
|
||||
$category->language = '*';
|
||||
$category->extension = 'com_weblinks';
|
||||
$category->title = 'Uncategorised';
|
||||
$category->description = '';
|
||||
$category->published = 1;
|
||||
$category->access = 1;
|
||||
$category->params = '{"category_layout":"","image":""}';
|
||||
$category->metadata = '{"author":"","robots":""}';
|
||||
$category->metadesc = '';
|
||||
$category->metakey = '';
|
||||
$category->language = '*';
|
||||
$category->checked_out_time = Factory::getDbo()->getNullDate();
|
||||
$category->version = 1;
|
||||
$category->hits = 0;
|
||||
$category->version = 1;
|
||||
$category->hits = 0;
|
||||
$category->modified_user_id = 0;
|
||||
$category->checked_out = 0;
|
||||
$category->checked_out = 0;
|
||||
|
||||
// Set the location in the tree
|
||||
$category->setLocation(1, 'last-child');
|
||||
@ -164,6 +165,9 @@ class Com_WeblinksInstallerScript
|
||||
|
||||
// Insert missing UCM Records if needed
|
||||
$this->insertMissingUcmRecords();
|
||||
|
||||
// Add Fields and Field Group menu items
|
||||
$this->addFieldsMenuItems();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -342,4 +346,159 @@ class Com_WeblinksInstallerScript
|
||||
$db->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to add update component_id of fields and field groups menu items for weblinks
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private function addFieldsMenuItems()
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$tableItem = new \Joomla\Component\Menus\Administrator\Table\MenuTable($db);
|
||||
|
||||
// Check for the Contact parent Id Menu Item
|
||||
$keys = [
|
||||
'menutype' => 'main',
|
||||
'type' => 'component',
|
||||
'title' => 'com_weblinks',
|
||||
'parent_id' => 1,
|
||||
'client_id' => 1,
|
||||
];
|
||||
|
||||
if (!$tableItem->load($keys))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$parentId = $tableItem->id;
|
||||
$componentId = ExtensionHelper::getExtensionRecord('com_fields', 'component')->extension_id;
|
||||
|
||||
// Add Weblinks Fields and Field Groups Menu Items.
|
||||
$menuItems = [
|
||||
[
|
||||
'menutype' => 'main',
|
||||
'title' => '-',
|
||||
'alias' => microtime(true),
|
||||
'note' => '',
|
||||
'path' => '',
|
||||
'link' => '#',
|
||||
'type' => 'separator',
|
||||
'published' => 1,
|
||||
'parent_id' => $parentId,
|
||||
'level' => 2,
|
||||
'component_id' => $componentId,
|
||||
'checked_out' => null,
|
||||
'checked_out_time' => null,
|
||||
'browserNav' => 0,
|
||||
'access' => 0,
|
||||
'img' => '',
|
||||
'template_style_id' => 0,
|
||||
'params' => '{}',
|
||||
'home' => 0,
|
||||
'language' => '*',
|
||||
'client_id' => 1,
|
||||
'publish_up' => null,
|
||||
'publish_down' => null,
|
||||
],
|
||||
[
|
||||
'menutype' => 'main',
|
||||
'title' => 'com_weblinks_fields',
|
||||
'alias' => 'com-weblinks-fields',
|
||||
'note' => '',
|
||||
'path' => 'com-weblinks/com-weblinks-fields',
|
||||
'link' => 'index.php?option=com_fields&context=com_weblinks.weblink',
|
||||
'type' => 'component',
|
||||
'published' => 1,
|
||||
'parent_id' => $parentId,
|
||||
'level' => 2,
|
||||
'component_id' => $componentId,
|
||||
'checked_out' => null,
|
||||
'checked_out_time' => null,
|
||||
'browserNav' => 0,
|
||||
'access' => 0,
|
||||
'img' => '',
|
||||
'template_style_id' => 0,
|
||||
'params' => '{}',
|
||||
'home' => 0,
|
||||
'language' => '*',
|
||||
'client_id' => 1,
|
||||
'publish_up' => null,
|
||||
'publish_down' => null,
|
||||
],
|
||||
[
|
||||
'menutype' => 'main',
|
||||
'title' => 'com_weblinks_field_groups',
|
||||
'alias' => 'com-weblinks-field-groups',
|
||||
'note' => '',
|
||||
'path' => 'com-weblinks/com-weblinks-field-groups',
|
||||
'link' => 'index.php?option=com_fields&view=groups&context=com_weblinks.weblink',
|
||||
'type' => 'component',
|
||||
'published' => 1,
|
||||
'parent_id' => $parentId,
|
||||
'level' => 2,
|
||||
'component_id' => $componentId,
|
||||
'checked_out' => null,
|
||||
'checked_out_time' => null,
|
||||
'browserNav' => 0,
|
||||
'access' => 0,
|
||||
'img' => '',
|
||||
'template_style_id' => 0,
|
||||
'params' => '{}',
|
||||
'home' => 0,
|
||||
'language' => '*',
|
||||
'client_id' => 1,
|
||||
'publish_up' => null,
|
||||
'publish_down' => null,
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
foreach ($menuItems as $menuItem)
|
||||
{
|
||||
// Check an existing record
|
||||
$keys = [
|
||||
'menutype' => $menuItem['menutype'],
|
||||
'type' => $menuItem['type'],
|
||||
'title' => $menuItem['title'],
|
||||
'parent_id' => $menuItem['parent_id'],
|
||||
'client_id' => $menuItem['client_id'],
|
||||
];
|
||||
|
||||
if ($tableItem->load($keys))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$newTableItem = new \Joomla\Component\Menus\Administrator\Table\MenuTable($db);
|
||||
|
||||
// Bind the data.
|
||||
if (!$newTableItem->bind($menuItem))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$newTableItem->setLocation($menuItem['parent_id'], 'last-child');
|
||||
|
||||
// Check the data.
|
||||
if (!$newTableItem->check())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Store the data.
|
||||
if (!$newTableItem->store())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Rebuild the tree path.
|
||||
if (!$newTableItem->rebuildPath($newTableItem->id))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -20,6 +20,8 @@ COM_WEBLINKS_FIELD_SELECT_WEBLINK_LABEL="Select Weblink"
|
||||
COM_WEBLINKS_FORM_VIEW_DEFAULT_DESC="Display a form to submit a web link in the Frontend."
|
||||
COM_WEBLINKS_FORM_VIEW_DEFAULT_OPTION="Default"
|
||||
COM_WEBLINKS_FORM_VIEW_DEFAULT_TITLE="Submit a Web Link"
|
||||
COM_WEBLINKS_FIELDS="Fields"
|
||||
COM_WEBLINKS_FIELD_GROUPS="Field Groups"
|
||||
COM_WEBLINKS_LINKS="Links"
|
||||
COM_WEBLINKS_TAGS_WEBLINK="Web Link"
|
||||
COM_WEBLINKS_TAGS_CATEGORY="Web Link Category"
|
||||
|
Loading…
Reference in New Issue
Block a user