- md5
- 504e15a845a853e2c8c14bc1258ae0eb
- sha1
- 43b888dbae239c8135736b1910f989f2c335f10f
- sha256
- a1fd59cd06b556ec521a2be20af8e4b1bb569c2866a40ec17e52b6c8006f94b7
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034
<?php
/**
* @package Joomla.Plugin
* @subpackage Sampledata.blog
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\SampleData\Blog\Extension;
use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Event\Plugin\AjaxEvent;
use Joomla\CMS\Event\SampleData\GetOverviewEvent;
use Joomla\CMS\Extension\ExtensionHelper;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Session\Session;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Database\ParameterType;
use Joomla\Event\SubscriberInterface;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Sampledata - Blog Plugin
*
* @since 3.8.0
*/
final class Blog extends CMSPlugin implements SubscriberInterface
{
use DatabaseAwareTrait;
/**
* Affects constructor behavior. If true, language files will be loaded automatically.
*
* @var boolean
*
* @since 3.8.0
*/
protected $autoloadLanguage = true;
/**
* Holds the menuitem model
*
* @var \Joomla\Component\Menus\Administrator\Model\ItemModel
*
* @since 3.8.0
*/
private $menuItemModel;
/**
* Returns an array of events this subscriber will listen to.
*
* @return array
*
* @since 5.3.0
*/
public static function getSubscribedEvents(): array
{
return [
'onSampledataGetOverview' => 'onSampledataGetOverview',
'onAjaxSampledataApplyStep1' => 'onAjaxSampledataApplyStep1',
'onAjaxSampledataApplyStep2' => 'onAjaxSampledataApplyStep2',
'onAjaxSampledataApplyStep3' => 'onAjaxSampledataApplyStep3',
'onAjaxSampledataApplyStep4' => 'onAjaxSampledataApplyStep4',
];
}
/**
* Get an overview of the proposed sampledata.
*
* @param GetOverviewEvent $event Event instance
*
* @return void
*
* @since 3.8.0
*/
public function onSampledataGetOverview(GetOverviewEvent $event): void
{
if (!$this->getApplication()->getIdentity()->authorise('core.create', 'com_content')) {
return;
}
$data = new \stdClass();
$data->name = $this->_name;
$data->title = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_OVERVIEW_TITLE');
$data->description = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_OVERVIEW_DESC');
$data->icon = 'wifi';
$data->steps = 4;
$event->addResult($data);
}
/**
* First step to enter the sampledata. Content.
*
* @param AjaxEvent $event Event instance
*
* @return void
*
* @since 3.8.0
*/
public function onAjaxSampledataApplyStep1(AjaxEvent $event): void
{
if (!Session::checkToken('get') || $this->getApplication()->getInput()->get('type') != $this->_name) {
return;
}
if (!ComponentHelper::isEnabled('com_tags')) {
$response = [];
$response['success'] = true;
$response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_SKIPPED', 1, 'com_tags');
$event->addResult($response);
return;
}
// Get some metadata.
$access = (int) $this->getApplication()->get('access', 1);
$user = $this->getApplication()->getIdentity();
// Detect language to be used.
$language = Multilanguage::isEnabled() ? $this->getApplication()->getLanguage()->getTag() : '*';
$langSuffix = ($language !== '*') ? ' (' . $language . ')' : '';
// Disable language debug to prevent debug_lang_const being added to the string
$this->getApplication()->getLanguage()->setDebug(false);
/** @var \Joomla\Component\Tags\Administrator\Model\TagModel $model */
$modelTag = $this->getApplication()->bootComponent('com_tags')->getMVCFactory()
->createModel('Tag', 'Administrator', ['ignore_request' => true]);
$tagIds = [];
// Create first three tags.
for ($i = 0; $i <= 3; $i++) {
$title = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_TAG_' . $i . '_TITLE') . $langSuffix;
$tag = [
'id' => 0,
'title' => $title,
'alias' => ApplicationHelper::stringURLSafe($title),
// Parent is root, except for the 4th tag. The 4th is child of the 3rd
'parent_id' => $i === 3 ? $tagIds[2] : 1,
'published' => 1,
'access' => $access,
'created_user_id' => $user->id,
'language' => $language,
'description' => '',
];
try {
if (!$modelTag->save($tag)) {
$this->getApplication()->getLanguage()->load('com_tags');
throw new \Exception($this->getApplication()->getLanguage()->_($modelTag->getError()));
}
} catch (\Exception $e) {
$response = [];
$response['success'] = false;
$response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 1, $e->getMessage());
$event->addResult($response);
return;
}
$tagIds[] = $modelTag->getItem()->id;
}
if (!ComponentHelper::isEnabled('com_content') || !$this->getApplication()->getIdentity()->authorise('core.create', 'com_content')) {
$response = [];
$response['success'] = true;
$response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_SKIPPED', 1, 'com_content');
$event->addResult($response);
return;
}
if (ComponentHelper::isEnabled('com_fields') && $user->authorise('core.create', 'com_fields')) {
$this->getApplication()->getLanguage()->load('com_fields');
$mvcFactory = $this->getApplication()->bootComponent('com_fields')->getMVCFactory();
$groupModel = $mvcFactory->createModel('Group', 'Administrator', ['ignore_request' => true]);
$group = [
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_FIELDS_GROUP_TITLE') . $langSuffix,
'id' => 0,
'published' => 1,
'ordering' => 0,
'note' => '',
'state' => 1,
'access' => $access,
'created_user_id' => $user->id,
'context' => 'com_content.article',
'description' => '',
'language' => $language,
'params' => '{"display_readonly":"1"}',
];
try {
if (!$groupModel->save($group)) {
throw new \Exception($groupModel->getError());
}
} catch (\Exception $e) {
$response = [];
$response['success'] = false;
$response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 1, $e->getMessage());
$event->addResult($response);
return;
}
$groupId = $groupModel->getItem()->id;
// Add fields
$fieldIds = [];
$articleFields = [
[
'type' => 'textarea',
'fieldparams' => [
'rows' => 3,
'cols' => 80,
'maxlength' => 400,
'filter' => '',
],
],
];
$fieldModel = $mvcFactory->createModel('Field', 'Administrator', ['ignore_request' => true]);
foreach ($articleFields as $i => $cf) {
// Set values from language strings.
$cfTitle = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_FIELDS_FIELD_' . $i . '_TITLE') . $langSuffix;
$cf['id'] = 0;
$cf['name'] = $cfTitle;
$cf['label'] = $cfTitle;
$cf['title'] = $cfTitle;
$cf['description'] = '';
$cf['note'] = '';
$cf['default_value'] = '';
$cf['group_id'] = $groupId;
$cf['ordering'] = 0;
$cf['state'] = 1;
$cf['language'] = $language;
$cf['access'] = $access;
$cf['context'] = 'com_content.article';
$cf['params'] = [
'hint' => '',
'class' => '',
'label_class' => '',
'show_on' => '',
'render_class' => '',
'showlabel' => '1',
'label_render_class' => '',
'display' => '3',
'prefix' => '',
'suffix' => '',
'layout' => '',
'display_readonly' => '2',
];
try {
if (!$fieldModel->save($cf)) {
throw new \Exception($fieldModel->getError());
}
} catch (\Exception $e) {
$response = [];
$response['success'] = false;
$response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 1, $e->getMessage());
$event->addResult($response);
return;
}
// Get ID from the field we just added
$fieldIds[] = $fieldModel->getItem()->id;
}
}
if (ComponentHelper::isEnabled('com_workflow') && $this->getApplication()->getIdentity()->authorise('core.create', 'com_workflow')) {
$this->getApplication()->bootComponent('com_workflow');
// Create workflow
$workflowTable = new \Joomla\Component\Workflow\Administrator\Table\WorkflowTable($this->getDatabase());
$workflowTable->default = 0;
$workflowTable->title = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_SAMPLE_TITLE') . $langSuffix;
$workflowTable->description = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_SAMPLE_DESCRIPTION');
$workflowTable->published = 1;
$workflowTable->access = $access;
$workflowTable->created_user_id = $user->id;
$workflowTable->extension = 'com_content.article';
if (!$workflowTable->store()) {
$response = [];
$response['success'] = false;
$response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 1, $this->getApplication()->getLanguage()->_($workflowTable->getError()));
$event->addResult($response);
return;
}
// Get ID from workflow we just added
$workflowId = $workflowTable->id;
// Create Stages.
for ($i = 1; $i <= 9; $i++) {
$stageTable = new \Joomla\Component\Workflow\Administrator\Table\StageTable($this->getDatabase());
// Set values from language strings.
$stageTable->title = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE' . $i . '_TITLE');
$stageTable->description = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE' . $i . '_DESCRIPTION');
// Set values which are always the same.
$stageTable->id = 0;
$stageTable->published = 1;
$stageTable->ordering = 0;
$stageTable->default = $i == 6 ? 1 : 0;
$stageTable->workflow_id = $workflowId;
if (!$stageTable->store()) {
$response = [];
$response['success'] = false;
$response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 1, $this->getApplication()->getLanguage()->_($stageTable->getError()));
$event->addResult($response);
return;
}
}
// Get the stage Ids of the new stages
$query = $this->getDatabase()->getQuery(true);
$query->select([$this->getDatabase()->quoteName('title'), $this->getDatabase()->quoteName('id')])
->from($this->getDatabase()->quoteName('#__workflow_stages'))
->where($this->getDatabase()->quoteName('workflow_id') . ' = :workflow_id')
->bind(':workflow_id', $workflowId, ParameterType::INTEGER);
$stages = $this->getDatabase()->setQuery($query)->loadAssocList('title', 'id');
// Prepare Transitions
$defaultOptions = json_encode(
[
'publishing' => 0,
'featuring' => 0,
'notification_send_mail' => false,
]
);
$fromTo = [
[
// Idea to Copywriting
'from_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE1_TITLE')],
'to_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE2_TITLE')],
'options' => $defaultOptions,
],
[
// Copywriting to Graphic Design
'from_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE2_TITLE')],
'to_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE3_TITLE')],
'options' => $defaultOptions,
],
[
// Graphic Design to Fact Check
'from_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE3_TITLE')],
'to_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE4_TITLE')],
'options' => $defaultOptions,
],
[
// Fact Check to Review
'from_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE4_TITLE')],
'to_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE5_TITLE')],
'options' => $defaultOptions,
],
[
// Edit article - revision to copy writer
'from_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE5_TITLE')],
'to_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE2_TITLE')],
'options' => $defaultOptions,
],
[
// Revision to published and featured
'from_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE5_TITLE')],
'to_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE6_TITLE')],
'options' => json_encode(
[
'publishing' => 1,
'featuring' => 1,
'notification_send_mail' => true,
'notification_text' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE6_TEXT'),
'notification_groups' => ["7"],
]
),
],
[
// All to on Hold
'from_stage_id' => -1,
'to_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE7_TITLE')],
'options' => json_encode(
[
'publishing' => 2,
'featuring' => 0,
'notification_send_mail' => false,
]
),
],
[
// Idea to trash
'from_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE1_TITLE')],
'to_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE8_TITLE')],
'options' => json_encode(
[
'publishing' => -2,
'featuring' => 0,
'notification_send_mail' => false,
]
),
],
[
// On Hold to Idea (Re-activate an idea)
'from_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE7_TITLE')],
'to_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE1_TITLE')],
'options' => $defaultOptions,
],
[
// Unpublish a published article
'from_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE6_TITLE')],
'to_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE9_TITLE')],
'options' => $defaultOptions,
],
[
// Trash a published article
'from_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE6_TITLE')],
'to_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE8_TITLE')],
'options' => $defaultOptions,
],
[
// From unpublished back to published
'from_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE9_TITLE')],
'to_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE6_TITLE')],
'options' => json_encode(
[
'publishing' => 1,
'featuring' => 0,
'notification_send_mail' => true,
'notification_text' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE6_TEXT'),
'notification_groups' => ["7"],
]
),
],
];
// Create Transitions.
foreach ($fromTo as $i => $item) {
$trTable = new \Joomla\Component\Workflow\Administrator\Table\TransitionTable($this->getDatabase());
$trTable->from_stage_id = $item['from_stage_id'];
$trTable->to_stage_id = $item['to_stage_id'];
$trTable->options = $item['options'];
// Set values from language strings.
$trTable->title = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_TRANSITION' . ($i + 1) . '_TITLE');
$trTable->description = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_TRANSITION' . ($i + 1) . '_DESCRIPTION');
// Set values which are always the same.
$trTable->id = 0;
$trTable->published = 1;
$trTable->ordering = 0;
$trTable->workflow_id = $workflowId;
if (!$trTable->store()) {
$response = [];
$response['success'] = false;
$response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 1, $this->getApplication()->getLanguage()->_($trTable->getError()));
$event->addResult($response);
return;
}
}
}
// Store the categories
$catIds = [];
for ($i = 0; $i <= 3; $i++) {
$categoryModel = $this->getApplication()->bootComponent('com_categories')
->getMVCFactory()->createModel('Category', 'Administrator');
$categoryTitle = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_CATEGORY_' . $i . '_TITLE');
$categoryAlias = ApplicationHelper::stringURLSafe($categoryTitle);
// Set unicodeslugs if alias is empty
if (trim(str_replace('-', '', $categoryAlias) == '')) {
$unicode = $this->getApplication()->set('unicodeslugs', 1);
$categoryAlias = ApplicationHelper::stringURLSafe($categoryTitle);
$this->getApplication()->set('unicodeslugs', $unicode);
}
// Category 0 gets the workflow from above
$params = $i == 0 ? '{"workflow_id":"' . $workflowId . '"}' : '{}';
$category = [
'title' => $categoryTitle . $langSuffix,
'parent_id' => 1,
'id' => 0,
'published' => 1,
'access' => $access,
'created_user_id' => $user->id,
'extension' => 'com_content',
'level' => 1,
'alias' => $categoryAlias . $langSuffix,
'associations' => [],
'description' => '',
'language' => $language,
'params' => $params,
];
try {
if (!$categoryModel->save($category)) {
$this->getApplication()->getLanguage()->load('com_categories');
throw new \Exception($categoryModel->getError());
}
} catch (\Exception $e) {
$response = [];
$response['success'] = false;
$response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 1, $e->getMessage());
$event->addResult($response);
return;
}
// Get ID from category we just added
$catIds[] = $categoryModel->getItem()->id;
}
// Create Articles.
$articles = [
// Category 1 = Help
[
// Article 0 - About
'catid' => $catIds[1],
],
[
// Article 1 - Working on Your Site
'catid' => $catIds[1],
'access' => 3,
],
// Category 0 = Blog
[
// Article 2 - Welcome to your blog
'catid' => $catIds[0],
'featured' => 1,
'tags' => array_map('strval', $tagIds),
'images' => [
'image_intro' => 'images/sampledata/cassiopeia/nasa1-1200.jpg#'
. 'joomlaImage://local-images/sampledata/cassiopeia/nasa1-1200.jpg?width=1200&height=400',
'float_intro' => '',
'image_intro_alt' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_2_INTROIMAGE_ALT'),
'image_intro_alt_empty' => '',
'image_intro_caption' => '',
'image_fulltext' => 'images/sampledata/cassiopeia/nasa1-400.jpg#'
. 'joomlaImage://local-images/sampledata/cassiopeia/nasa1-400.jpg?width=400&height=400',
'float_fulltext' => 'float-start',
'image_fulltext_alt' => '',
'image_fulltext_alt_empty' => 1,
'image_fulltext_caption' => 'www.nasa.gov/multimedia/imagegallery',
],
],
[
// Article 3 - About your home page
'catid' => $catIds[0],
'featured' => 1,
'tags' => array_map('strval', $tagIds),
'images' => [
'image_intro' => 'images/sampledata/cassiopeia/nasa2-1200.jpg#'
. 'joomlaImage://local-images/sampledata/cassiopeia/nasa2-1200.jpg?width=1200&height=400',
'float_intro' => '',
'image_intro_alt' => '',
'image_intro_alt_empty' => 1,
'image_intro_caption' => '',
'image_fulltext' => 'images/sampledata/cassiopeia/nasa2-400.jpg#'
. 'joomlaImage://local-images/sampledata/cassiopeia/nasa2-400.jpg?width=400&height=400',
'float_fulltext' => 'float-start',
'image_fulltext_alt' => '',
'image_fulltext_alt_empty' => 1,
'image_fulltext_caption' => 'www.nasa.gov/multimedia/imagegallery',
],
'authorValue' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_3_FIELD_0'),
],
[
// Article 4 - Your Modules
'catid' => $catIds[0],
'featured' => 1,
'tags' => array_map('strval', $tagIds),
'images' => [
'image_intro' => 'images/sampledata/cassiopeia/nasa3-1200.jpg#'
. 'joomlaImage://local-images/sampledata/cassiopeia/nasa3-1200.jpg?width=1200&height=400',
'float_intro' => '',
'image_intro_alt' => '',
'image_intro_alt_empty' => 1,
'image_intro_caption' => '',
'image_fulltext' => 'images/sampledata/cassiopeia/nasa3-400.jpg#'
. 'joomlaImage://local-images/sampledata/cassiopeia/nasa3-400.jpg?width=400&height=400',
'float_fulltext' => 'float-start',
'image_fulltext_alt' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_4_FULLTEXTIMAGE_ALT'),
'image_fulltext_alt_empty' => '',
'image_fulltext_caption' => 'www.nasa.gov/multimedia/imagegallery',
],
],
[
// Article 5 - Your Template
'catid' => $catIds[0],
'featured' => 1,
'tags' => array_map('strval', $tagIds),
'images' => [
'image_intro' => 'images/sampledata/cassiopeia/nasa4-1200.jpg#'
. 'joomlaImage://local-images/sampledata/cassiopeia/nasa4-1200.jpg?width=1200&height=400',
'float_intro' => '',
'image_intro_alt' => '',
'image_intro_alt_empty' => 1,
'image_intro_caption' => '',
'image_fulltext' => 'images/sampledata/cassiopeia/nasa4-400.jpg#'
. 'joomlaImage://local-images/sampledata/cassiopeia/nasa4-400.jpg?width=400&height=400',
'float_fulltext' => 'float-start',
'image_fulltext_alt' => '',
'image_fulltext_alt_empty' => 1,
'image_fulltext_caption' => 'www.nasa.gov/multimedia/imagegallery',
],
],
// Category 2 = Joomla - marketing texts
[
// Article 6 - Millions
'catid' => $catIds[2],
'images' => [
'image_intro' => 'images/sampledata/cassiopeia/nasa1-640.jpg#'
. 'joomlaImage://local-images/sampledata/cassiopeia/nasa1-640.jpg?width=640&height=320',
'float_intro' => '',
'image_intro_alt' => '',
'image_intro_alt_empty' => 1,
'image_intro_caption' => '',
],
],
[
// Article 7 - Love
'catid' => $catIds[2],
'images' => [
'image_intro' => 'images/sampledata/cassiopeia/nasa2-640.jpg#'
. 'joomlaImage://local-images/sampledata/cassiopeia/nasa2-640.jpg?width=640&height=320',
'float_intro' => '',
'image_intro_alt' => '',
'image_intro_alt_empty' => 1,
'image_intro_caption' => '',
],
],
[
// Article 8 - Joomla
'catid' => $catIds[2],
'images' => [
'image_intro' => 'images/sampledata/cassiopeia/nasa3-640.jpg#'
. 'joomlaImage://local-images/sampledata/cassiopeia/nasa3-640.jpg?width=640&height=320',
'float_intro' => '',
'image_intro_alt' => '',
'image_intro_alt_empty' => 1,
'image_intro_caption' => '',
],
],
[
// Article 9 - Workflows
'catid' => $catIds[1],
'images' => [
'image_intro' => '',
'float_intro' => '',
'image_intro_alt' => '',
'image_intro_alt_empty' => '',
'image_intro_caption' => '',
'image_fulltext' => 'images/sampledata/cassiopeia/nasa4-400.jpg#'
. 'joomlaImage://local-images/sampledata/cassiopeia/nasa4-400.jpg?width=400&height=400',
'float_fulltext' => 'float-end',
'image_fulltext_alt' => '',
'image_fulltext_alt_empty' => 1,
'image_fulltext_caption' => 'www.nasa.gov/multimedia/imagegallery',
],
'authorValue' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_9_FIELD_0'),
],
// Category 3 - Typography
[
// Article 10 - Typography
'catid' => $catIds[3],
],
];
$mvcFactory = $this->getApplication()->bootComponent('com_content')->getMVCFactory();
// Store the articles
foreach ($articles as $i => $article) {
$articleModel = $mvcFactory->createModel('Article', 'Administrator', ['ignore_request' => true]);
// Set values from language strings.
$title = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_' . $i . '_TITLE');
$alias = ApplicationHelper::stringURLSafe($title);
$article['title'] = $title . $langSuffix;
$article['introtext'] = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_' . $i . '_INTROTEXT');
$article['fulltext'] = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_' . $i . '_FULLTEXT');
// Set values which are always the same.
$article['id'] = 0;
$article['ordering'] = 0;
$article['created_user_id'] = $user->id;
$article['created_by_alias'] = 'Joomla';
$article['alias'] = ApplicationHelper::stringURLSafe($article['title']);
// Set unicodeslugs if alias is empty
if (trim(str_replace('-', '', $alias) == '')) {
$unicode = $this->getApplication()->set('unicodeslugs', 1);
$article['alias'] = ApplicationHelper::stringURLSafe($article['title']);
$this->getApplication()->set('unicodeslugs', $unicode);
}
$article['language'] = $language;
$article['associations'] = [];
$article['metakey'] = '';
$article['metadesc'] = '';
if (!isset($article['featured'])) {
$article['featured'] = 0;
}
if (!isset($article['state'])) {
$article['state'] = 1;
}
if (!isset($article['images'])) {
$article['images'] = '';
}
if (!isset($article['access'])) {
$article['access'] = $access;
}
if (!$articleModel->save($article)) {
$response = [];
$response['success'] = false;
$response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 1, $this->getApplication()->getLanguage()->_($articleModel->getError()));
$event->addResult($response);
return;
}
// Get ID from article we just added
$ids[] = $articleModel->getItem()->id;
if (
$article['featured']
&& ComponentHelper::isEnabled('com_workflow')
&& PluginHelper::isEnabled('workflow', 'featuring')
&& ComponentHelper::getParams('com_content')->get('workflow_enabled')
) {
// Set the article featured in #__content_frontpage
$this->getDatabase()->getQuery(true);
$featuredItem = (object) [
'content_id' => $articleModel->getItem()->id,
'ordering' => 0,
'featured_up' => null,
'featured_down' => null,
];
$this->getDatabase()->insertObject('#__content_frontpage', $featuredItem);
}
// Add a value to the custom field if a value is given
if (ComponentHelper::isEnabled('com_fields') && $this->getApplication()->getIdentity()->authorise('core.create', 'com_fields')) {
if (!empty($article['authorValue'])) {
// Store a field value
$valueAuthor = (object) [
'item_id' => $articleModel->getItem()->id,
'field_id' => $fieldIds[0],
'value' => $article['authorValue'],
];
$this->getDatabase()->insertObject('#__fields_values', $valueAuthor);
}
}
}
$this->getApplication()->setUserState('sampledata.blog.articles', $ids);
$this->getApplication()->setUserState('sampledata.blog.articles.catIds', $catIds);
$response = [];
$response['success'] = true;
$response['message'] = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_STEP1_SUCCESS');
$event->addResult($response);
}
/**
* Second step to enter the sampledata. Menus.
*
* @param AjaxEvent $event Event instance
*
* @return void
*
* @since 3.8.0
*/
public function onAjaxSampledataApplyStep2(AjaxEvent $event): void
{
if (!Session::checkToken('get') || $this->getApplication()->getInput()->get('type') != $this->_name) {
return;
}
if (!ComponentHelper::isEnabled('com_menus') || !$this->getApplication()->getIdentity()->authorise('core.create', 'com_menus')) {
$response = [];
$response['success'] = true;
$response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_SKIPPED', 2, 'com_menus');
$event->addResult($response);
return;
}
// Detect language to be used.
$language = Multilanguage::isEnabled() ? $this->getApplication()->getLanguage()->getTag() : '*';
$langSuffix = ($language !== '*') ? ' (' . $language . ')' : '';
// Disable language debug to prevent debug_lang_const being added to the string
$this->getApplication()->getLanguage()->setDebug(false);
// Create the menu types.
$menuTable = new \Joomla\Component\Menus\Administrator\Table\MenuTypeTable($this->getDatabase());
$menuTypes = [];
for ($i = 0; $i <= 2; $i++) {
$title = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_MENU_' . $i . '_TITLE');
$menu = [
'id' => 0,
'title' => $title . ' ' . $langSuffix,
'description' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_MENU_' . $i . '_DESCRIPTION'),
];
// Calculate menutype. The maximum number of characters allowed is 24.
$menu['menutype'] = $i . HTMLHelper::_('string.truncate', $title, 16, true, false) . $langSuffix;
try {
$menuTable->load();
$menuTable->bind($menu);
if (!$menuTable->check()) {
$this->getApplication()->getLanguage()->load('com_menu');
throw new \Exception($menuTable->getError());
}
$menuTable->store();
} catch (\Exception $e) {
$response = [];
$response['success'] = false;
$response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 2, $e->getMessage());
$event->addResult($response);
return;
}
$menuTypes[] = $menuTable->menutype;
}
// Storing IDs in UserState for later usage.
$this->getApplication()->setUserState('sampledata.blog.menutypes', $menuTypes);
// Get previously entered Data from UserStates.
$articleIds = $this->getApplication()->getUserState('sampledata.blog.articles');
// Get MenuItemModel.
$this->menuItemModel = $this->getApplication()->bootComponent('com_menus')->getMVCFactory()
->createModel('Item', 'Administrator', ['ignore_request' => true]);
// Get previously entered categories ids
$catIds = $this->getApplication()->getUserState('sampledata.blog.articles.catIds');
// Link to the homepage from logout
$home = $this->getApplication()->getMenu('site')->getDefault()->id;
if (Multilanguage::isEnabled()) {
$homes = Multilanguage::getSiteHomePages();
if (isset($homes[$language])) {
$home = $homes[$language]->id;
}
}
// Insert menuitems level 1.
$menuItems = [
[
// Blog
'menutype' => $menuTypes[0],
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_0_TITLE'),
'link' => 'index.php?option=com_content&view=category&layout=blog&id=' . $catIds[0],
'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
'params' => [
'layout_type' => 'blog',
'show_category_title' => 0,
'num_leading_articles' => 4,
'num_intro_articles' => 4,
'num_links' => 0,
'orderby_sec' => 'rdate',
'order_date' => 'published',
'blog_class_leading' => 'boxed columns-2',
'show_pagination' => 2,
'secure' => 0,
'show_page_heading' => 1,
],
],
[
// Help
'menutype' => $menuTypes[0],
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_CATEGORY_1_TITLE'),
'link' => 'index.php?option=com_content&view=category&layout=blog&id=' . $catIds[1],
'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
'params' => [
'blog_class_leading' => '',
'blog_class' => 'boxed',
'num_leading_articles' => 0,
'num_intro_articles' => 4,
'num_links' => 0,
'orderby_sec' => 'rdate',
'order_date' => 'published',
'show_pagination' => 4,
'show_pagination_results' => 1,
'article_layout' => '_:default',
'link_titles' => 0,
'info_block_show_title' => '',
'show_category' => 0,
'link_category' => '',
'show_parent_category' => '',
'link_parent_category' => '',
'show_author' => 0,
'link_author' => '',
'show_create_date' => 0,
'show_modify_date' => '',
'show_publish_date' => 0,
'show_hits' => 0,
'menu_text' => 1,
'menu_show' => 1,
'show_page_heading' => 1,
'secure' => 0,
],
],
[
// Login
'menutype' => $menuTypes[0],
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_2_TITLE'),
'link' => 'index.php?option=com_users&view=login',
'component_id' => ExtensionHelper::getExtensionRecord('com_users', 'component')->extension_id,
'access' => 5,
'params' => [
'loginredirectchoice' => '1',
'login_redirect_url' => '',
'login_redirect_menuitem' => $home,
'logoutredirectchoice' => '1',
'logout_redirect_url' => '',
'logout_redirect_menuitem' => $home,
'secure' => 0,
],
],
[
// Logout
'menutype' => $menuTypes[0],
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_16_TITLE'),
'link' => 'index.php?option=com_users&view=login&layout=logout&task=user.menulogout',
'component_id' => ExtensionHelper::getExtensionRecord('com_users', 'component')->extension_id,
'access' => 2,
'params' => [
'logout' => $home,
'secure' => 0,
],
],
[
// Sample metismenu (heading)
'menutype' => $menuTypes[0],
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_11_TITLE'),
'type' => 'heading',
'link' => '',
'component_id' => 0,
'params' => [
'layout_type' => 'heading',
'menu_text' => 1,
'show_page_heading' => 0,
'secure' => 0,
],
],
[
// Typography
'menutype' => $menuTypes[0],
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_14_TITLE'),
'link' => 'index.php?option=com_content&view=article&id=' . (int) $articleIds[10] . '&catid=' . (int) $catIds[3],
'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
'params' => [
'show_title' => 0,
'link_titles' => 0,
'show_intro' => 1,
'info_block_position' => '',
'info_block_show_title' => 0,
'show_category' => 0,
'show_author' => 0,
'show_create_date' => 0,
'show_modify_date' => 0,
'show_publish_date' => 0,
'show_item_navigation' => 0,
'show_hits' => 0,
'show_tags' => 0,
'menu_text' => 1,
'menu_show' => 1,
'page_title' => '',
'secure' => 0,
],
],
[
'menutype' => $menuTypes[1],
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_3_TITLE'),
'link' => 'index.php?option=com_content&view=form&layout=edit',
'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
'access' => 3,
'params' => [
'enable_category' => 1,
'catid' => $catIds[0],
'menu_text' => 1,
'show_page_heading' => 0,
'secure' => 0,
],
],
[
'menutype' => $menuTypes[1],
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_4_TITLE'),
'link' => 'index.php?option=com_content&view=article&id=' . $articleIds[1],
'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
'params' => [
'menu_text' => 1,
'show_page_heading' => 0,
'secure' => 0,
],
],
[
'menutype' => $menuTypes[1],
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_5_TITLE'),
'link' => 'administrator',
'type' => 'url',
'component_id' => 0,
'browserNav' => 1,
'access' => 3,
'params' => [
'menu_text' => 1,
'secure' => 0,
],
],
[
'menutype' => $menuTypes[1],
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_6_TITLE'),
'link' => 'index.php?option=com_users&view=profile&layout=edit',
'component_id' => ExtensionHelper::getExtensionRecord('com_users', 'component')->extension_id,
'access' => 2,
'params' => [
'menu_text' => 1,
'show_page_heading' => 0,
'secure' => 0,
],
],
[
'menutype' => $menuTypes[1],
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_7_TITLE'),
'link' => 'index.php?option=com_users&view=login',
'component_id' => ExtensionHelper::getExtensionRecord('com_users', 'component')->extension_id,
'params' => [
'logindescription_show' => 1,
'logoutdescription_show' => 1,
'menu_text' => 1,
'show_page_heading' => 0,
'secure' => 0,
],
],
];
try {
$menuIdsLevel1 = $this->addMenuItems($menuItems, 1);
} catch (\Exception $e) {
$response = [];
$response['success'] = false;
$response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 2, $e->getMessage());
$event->addResult($response);
return;
}
// Insert level 1 (Link in the footer as alias)
$menuItems = [
[
'menutype' => $menuTypes[2],
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_8_TITLE'),
'link' => 'index.php?Itemid=',
'type' => 'alias',
'access' => 5,
'params' => [
'aliasoptions' => $menuIdsLevel1[2],
'alias_redirect' => 0,
'menu-anchor_title' => '',
'menu-anchor_css' => '',
'menu_image' => '',
'menu_image_css' => '',
'menu_text' => 1,
'menu_show' => 1,
'secure' => 0,
],
],
[
'menutype' => $menuTypes[2],
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_16_TITLE'),
'link' => 'index.php?Itemid=',
'type' => 'alias',
'access' => 2,
'params' => [
'aliasoptions' => $menuIdsLevel1[3],
'alias_redirect' => 0,
'menu-anchor_title' => '',
'menu-anchor_css' => '',
'menu_image' => '',
'menu_image_css' => '',
'menu_text' => 1,
'menu_show' => 1,
'secure' => 0,
],
],
[
// Hidden menuItem search
'menutype' => $menuTypes[2],
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_15_TITLE'),
'link' => 'index.php?option=com_finder&view=search',
'type' => 'component',
'component_id' => ExtensionHelper::getExtensionRecord('com_finder', 'component')->extension_id,
'params' => [
'show_date_filters' => '1',
'show_advanced' => '',
'expand_advanced' => '1',
'show_taxonomy' => '1',
'show_date' => '1',
'show_url' => '1',
'menu_text' => 0,
'menu_show' => 0,
'secure' => 0,
],
],
];
try {
$menuIdsLevel1 = array_merge($menuIdsLevel1, $this->addMenuItems($menuItems, 1));
} catch (\Exception $e) {
$response = [];
$response['success'] = false;
$response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 2, $e->getMessage());
$event->addResult($response);
return;
}
$this->getApplication()->setUserState('sampledata.blog.menuIdsLevel1', $menuIdsLevel1);
// Insert menuitems level 2.
$menuItems = [
[
'menutype' => $menuTypes[1],
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_9_TITLE'),
'link' => 'index.php?option=com_config&view=config',
'parent_id' => $menuIdsLevel1[6],
'component_id' => ExtensionHelper::getExtensionRecord('com_config', 'component')->extension_id,
'access' => 6,
'params' => [
'menu_text' => 1,
'show_page_heading' => 0,
'secure' => 0,
],
],
[
'menutype' => $menuTypes[1],
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_10_TITLE'),
'link' => 'index.php?option=com_config&view=templates',
'parent_id' => $menuIdsLevel1[6],
'component_id' => ExtensionHelper::getExtensionRecord('com_config', 'component')->extension_id,
'access' => 6,
'params' => [
'menu_text' => 1,
'show_page_heading' => 0,
'secure' => 0,
],
],
[
// Blog
'menutype' => $menuTypes[0],
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_0_TITLE'),
'link' => 'index.php?option=com_content&view=category&layout=blog&id=' . $catIds[0],
'parent_id' => $menuIdsLevel1[4],
'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
'params' => [
'layout_type' => 'blog',
'show_category_title' => 0,
'num_leading_articles' => 1,
'num_intro_articles' => 2,
'num_links' => 2,
'orderby_sec' => 'front',
'order_date' => 'published',
'blog_class_leading' => 'boxed columns-1',
'blog_class' => 'columns-2',
'show_pagination' => 2,
'show_pagination_results' => 1,
'show_category' => 0,
'info_bloc_position' => 0,
'show_publish_date' => 0,
'show_hits' => 0,
'show_feed_link' => 0,
'menu_text' => 1,
'show_page_heading' => 0,
'secure' => 0,
],
],
[
// Category List
'menutype' => $menuTypes[0],
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_12_TITLE'),
'link' => 'index.php?option=com_content&view=category&id=' . $catIds[0],
'parent_id' => $menuIdsLevel1[4],
'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
'params' => [
'menu_text' => 1,
'show_page_heading' => 1,
'secure' => 0,
],
],
[
// Articles (menu header)
'menutype' => $menuTypes[0],
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_13_TITLE'),
'link' => 'index.php?option=com_content&view=category&layout=blog&id=' . $catIds[2],
'parent_id' => $menuIdsLevel1[4],
'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
'params' => [
'layout_type' => 'blog',
'show_category_title' => 0,
'num_leading_articles' => 3,
'num_intro_articles' => 0,
'num_links' => 2,
'orderby_sec' => 'front',
'order_date' => 'published',
'blog_class_leading' => 'boxed columns-3',
'blog_class' => '',
'show_pagination' => 2,
'show_pagination_results' => 1,
'show_category' => 0,
'info_bloc_position' => 0,
'show_publish_date' => 0,
'show_hits' => 0,
'show_feed_link' => 0,
'menu_text' => 1,
'show_page_heading' => 0,
'secure' => 0,
],
],
[
'menutype' => $menuTypes[0],
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_3_TITLE'),
'link' => 'index.php?option=com_content&view=article&id=' . (int) $articleIds[3],
'parent_id' => $menuIdsLevel1[1],
'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
'params' => [
'menu_show' => 1,
'show_page_heading' => 0,
'secure' => 0,
],
],
[
'menutype' => $menuTypes[0],
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_9_TITLE'),
'link' => 'index.php?option=com_content&view=article&id=' . (int) $articleIds[9],
'parent_id' => $menuIdsLevel1[1],
'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
'params' => [
'menu_show' => 1,
'show_page_heading' => 0,
'secure' => 0,
],
],
];
try {
$menuIdsLevel2 = $this->addMenuItems($menuItems, 2);
} catch (\Exception $e) {
$response = [];
$response['success'] = false;
$response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 2, $e->getMessage());
$event->addResult($response);
return;
}
// Add a third level of menuItems - use article title also for menuItem title
$menuItems = [
[
'menutype' => $menuTypes[0],
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_6_TITLE'),
'link' => 'index.php?option=com_content&view=article&id=' . (int) $articleIds[6],
'parent_id' => $menuIdsLevel2[4],
'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
'params' => [
'menu_show' => 1,
'secure' => 0,
],
],
[
'menutype' => $menuTypes[0],
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_7_TITLE'),
'link' => 'index.php?option=com_content&view=article&id=' . (int) $articleIds[7],
'parent_id' => $menuIdsLevel2[4],
'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
'params' => [
'menu_show' => 1,
'secure' => 0,
],
],
[
'menutype' => $menuTypes[0],
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_8_TITLE'),
'link' => 'index.php?option=com_content&view=article&id=' . (int) $articleIds[8],
'parent_id' => $menuIdsLevel2[4],
'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
'params' => [
'menu_show' => 1,
'secure' => 0,
],
],
];
try {
$this->addMenuItems($menuItems, 3);
} catch (\Exception $e) {
$response = [];
$response['success'] = false;
$response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 2, $e->getMessage());
$event->addResult($response);
return;
}
$response = [];
$response['success'] = true;
$response['message'] = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_STEP2_SUCCESS');
$event->addResult($response);
}
/**
* Third step to enter the sampledata. Modules.
*
* @param AjaxEvent $event Event instance
*
* @return void
*
* @since 3.8.0
*/
public function onAjaxSampledataApplyStep3(AjaxEvent $event): void
{
if (!Session::checkToken('get') || $this->getApplication()->getInput()->get('type') != $this->_name) {
return;
}
$this->getApplication()->getLanguage()->load('com_modules');
if (!ComponentHelper::isEnabled('com_modules') || !$this->getApplication()->getIdentity()->authorise('core.create', 'com_modules')) {
$response = [];
$response['success'] = true;
$response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_SKIPPED', 3, 'com_modules');
$event->addResult($response);
return;
}
// Detect language to be used.
$language = Multilanguage::isEnabled() ? $this->getApplication()->getLanguage()->getTag() : '*';
$langSuffix = ($language !== '*') ? ' (' . $language . ')' : '';
// Disable language debug to prevent debug_lang_const being added to the string
$this->getApplication()->getLanguage()->setDebug(false);
// Add Include Paths.
/** @var \Joomla\Component\Modules\Administrator\Model\ModuleModel $model */
$model = $this->getApplication()->bootComponent('com_modules')->getMVCFactory()
->createModel('Module', 'Administrator', ['ignore_request' => true]);
$access = (int) $this->getApplication()->get('access', 1);
// Get previously entered Data from UserStates.
$articleIds = $this->getApplication()->getUserState('sampledata.blog.articles');
// Get previously entered Data from UserStates
$menuTypes = $this->getApplication()->getUserState('sampledata.blog.menutypes');
// Get previously entered categories ids
$catIds = $this->getApplication()->getUserState('sampledata.blog.articles.catIds');
// Link to article "typography" in banner module
$headerLink = 'index.php?option=com_content&view=article&id=' . (int) $articleIds[10] . '&catid=' . (int) $catIds[3];
$modules = [
[
// The main menu Blog
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_0_TITLE'),
'ordering' => 1,
'position' => 'menu',
'module' => 'mod_menu',
'showtitle' => 0,
'params' => [
'menutype' => $menuTypes[0],
'layout' => 'cassiopeia:collapse-metismenu',
'startLevel' => 1,
'endLevel' => 0,
'showAllChildren' => 1,
'class_sfx' => '',
'cache' => 1,
'cache_time' => 900,
'cachemode' => 'itemid',
'module_tag' => 'nav',
'bootstrap_size' => 0,
'header_tag' => 'h3',
'style' => 0,
],
],
[
// The author Menu, for registered users
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_1_TITLE'),
'ordering' => 1,
'position' => 'sidebar-right',
'module' => 'mod_menu',
'access' => 3,
'showtitle' => 0,
'params' => [
'menutype' => $menuTypes[1],
'startLevel' => 1,
'endLevel' => 0,
'showAllChildren' => 1,
'class_sfx' => '',
'layout' => '_:default',
'cache' => 1,
'cache_time' => 900,
'cachemode' => 'itemid',
'module_tag' => 'aside',
'bootstrap_size' => 0,
'header_tag' => 'h3',
'style' => 0,
],
],
[
// Syndication
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_2_TITLE'),
'ordering' => 6,
'position' => 'sidebar-right',
'module' => 'mod_syndicate',
'showtitle' => 0,
'params' => [
'display_text' => 1,
'text' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_NEWSFEEDS_TITLE'),
'format' => 'rss',
'layout' => '_:default',
'cache' => 0,
'module_tag' => 'section',
],
],
[
// Archived Articles
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_3_TITLE'),
'ordering' => 4,
'position' => 'sidebar-right',
'module' => 'mod_articles',
'params' => [
'mode' => 'normal',
'show_on_article_page' => 1,
'count' => 10,
'category_filtering_type' => 1,
'show_child_category_articles' => 0,
'levels' => 1,
'ex_or_include_articles' => 0,
'exclude_current' => 1,
'excluded_articles' => '',
'included_articles' => '',
'title_only' => 1,
'articles_layout' => 0,
'layout_columns' => 3,
'item_title' => 0,
'item_heading' => 'h4',
'link_titles' => 1,
'show_author' => 0,
'show_category' => 0,
'show_category_link' => 0,
'show_date' => 0,
'show_date_field' => 'created',
'show_date_format' => $this->getApplication()->getLanguage()->_('DATE_FORMAT_LC5'),
'show_hits' => 0,
'info_layout' => 0,
'show_tags' => 0,
'trigger_events' => 0,
'show_introtext' => 0,
'introtext_limit' => 100,
'image' => 0,
'img_intro_full' => 'none',
'show_readmore' => 0,
'show_readmore_title' => 1,
'readmore_limit' => 15,
'show_featured' => 'show',
'show_archived' => 'show',
'author_filtering_type' => 1,
'author_alias_filtering_type' => 1,
'date_filtering' => 'off',
'date_field' => 'a.created',
'start_date_range' => '',
'end_date_range' => '',
'relative_date' => 30,
'article_ordering' => 'a.title',
'article_ordering_direction' => 'ASC',
'article_grouping' => 'month_year',
'date_grouping_field' => 'created',
'month_year_format' => 'F Y',
'article_grouping_direction' => 'ksort',
'layout' => '_:default',
'moduleclass_sfx' => '',
'owncache' => 1,
'cache_time' => 900,
'module_tag' => 'div',
'bootstrap_size' => 0,
'header_tag' => 'h3',
'header_class' => '',
'style' => 0,
],
],
[
// Latest Posts
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_4_TITLE'),
'ordering' => 6,
'position' => 'top-a',
'module' => 'mod_articles',
// Assignment 1 means here - only on the homepage
'assignment' => 1,
'showtitle' => 0,
'params' => [
'mode' => 'normal',
'show_on_article_page' => 1,
'count' => 3,
'category_filtering_type' => 1,
'catid' => $catIds[2],
'show_child_category_articles' => 0,
'levels' => 1,
'ex_or_include_articles' => 0,
'exclude_current' => 1,
'excluded_articles' => '',
'included_articles' => '',
'title_only' => 0,
'articles_layout' => 1,
'layout_columns' => 3,
'item_title' => 1,
'item_heading' => 'h3',
'link_titles' => 1,
'show_author' => 0,
'show_category' => 0,
'show_category_link' => 1,
'show_date' => 0,
'show_date_field' => 'created',
'show_date_format' => $this->getApplication()->getLanguage()->_('DATE_FORMAT_LC5'),
'show_hits' => 0,
'info_layout' => 1,
'show_tags' => 0,
'trigger_events' => 0,
'show_introtext' => 1,
'introtext_limit' => 0,
'image' => 0,
'img_intro_full' => 'intro',
'show_readmore' => 1,
'show_readmore_title' => 1,
'readmore_limit' => 100,
'show_featured' => 'show',
'show_archived' => 'hide',
'author_filtering_type' => 1,
'author_alias_filtering_type' => 1,
'date_filtering' => 'off',
'date_field' => 'a.created',
'start_date_range' => '',
'end_date_range' => '',
'relative_date' => 30,
'article_ordering' => 'a.title',
'article_ordering_direction' => 'ASC',
'article_grouping' => 'none',
'date_grouping_field' => 'created',
'month_year_format' => 'F Y',
'article_grouping_direction' => 'ksort',
'layout' => '_:default',
'moduleclass_sfx' => '',
'owncache' => 1,
'cache_time' => 900,
'module_tag' => 'div',
'bootstrap_size' => 0,
'header_tag' => 'h3',
'header_class' => '',
'style' => 'Cassiopeia-noCard',
],
],
[
// Older Posts (from category 0 = blog)
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_5_TITLE'),
'ordering' => 2,
'position' => 'bottom-b',
'module' => 'mod_articles',
'params' => [
'mode' => 'normal',
'show_on_article_page' => 1,
'count' => 6,
'category_filtering_type' => 1,
'catid' => $catIds[0],
'show_child_category_articles' => 0,
'levels' => 1,
'ex_or_include_articles' => 0,
'exclude_current' => 1,
'excluded_articles' => '',
'included_articles' => '',
'title_only' => 1,
'articles_layout' => 0,
'layout_columns' => 3,
'item_title' => 0,
'item_heading' => 'h4',
'link_titles' => 1,
'show_author' => 0,
'show_category' => 0,
'show_category_link' => 0,
'show_date' => 0,
'show_date_field' => 'created',
'show_date_format' => $this->getApplication()->getLanguage()->_('DATE_FORMAT_LC5'),
'show_hits' => 0,
'info_layout' => 0,
'show_tags' => 0,
'trigger_events' => 0,
'show_introtext' => 0,
'introtext_limit' => 100,
'image' => 0,
'img_intro_full' => 'none',
'show_readmore' => 0,
'show_readmore_title' => 1,
'readmore_limit' => 15,
'show_featured' => 'show',
'show_archived' => 'hide',
'author_filtering_type' => 1,
'author_alias_filtering_type' => 1,
'date_filtering' => 'off',
'date_field' => 'a.created',
'start_date_range' => '',
'end_date_range' => '',
'relative_date' => 30,
'article_ordering' => 'a.created',
'article_ordering_direction' => 'ASC',
'article_grouping' => 'none',
'date_grouping_field' => 'created',
'month_year_format' => 'F Y',
'article_grouping_direction' => 'ksort',
'layout' => '_:default',
'moduleclass_sfx' => '',
'owncache' => 1,
'cache_time' => 900,
'module_tag' => 'div',
'bootstrap_size' => 0,
'header_tag' => 'h3',
'header_class' => '',
'style' => 0,
],
],
[
// Bottom Menu
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_6_TITLE'),
'ordering' => 1,
'position' => 'footer',
'module' => 'mod_menu',
'showtitle' => 0,
'params' => [
'menutype' => $menuTypes[2],
'class_sfx' => 'menu-horizontal',
'startLevel' => 1,
'endLevel' => 0,
'showAllChildren' => 0,
'layout' => 'cassiopeia:dropdown-metismenu',
'cache' => 1,
'cache_time' => 900,
'cachemode' => 'itemid',
'module_tag' => 'div',
'bootstrap_size' => 0,
'header_tag' => 'h3',
'style' => 0,
],
],
[
// Search
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_7_TITLE'),
'ordering' => 1,
'position' => 'search',
'module' => 'mod_finder',
'params' => [
'searchfilter' => '',
'show_autosuggest' => 1,
'show_advanced' => 0,
'show_label' => 0,
'alt_label' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_7_TITLE'),
'show_button' => 1,
'opensearch' => 1,
'opensearch_name' => '',
'set_itemid' => 0,
'layout' => '_:default',
'module_tag' => 'search',
],
],
[
// Header image
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_8_TITLE'),
'content' => '<p>' . Text::sprintf('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_8_CONTENT', $headerLink) . '</p>',
'ordering' => 1,
'position' => 'banner',
'module' => 'mod_custom',
// Assignment 1 means here - only on the homepage
'assignment' => 1,
'showtitle' => 0,
'params' => [
'prepare_content' => 0,
'backgroundimage' => 'images/banners/banner.jpg#joomlaImage://local-images/banners/banner.jpg?width=1140&height=600',
'layout' => 'cassiopeia:banner',
'moduleclass_sfx' => '',
'cache' => 1,
'cache_time' => 900,
'cachemode' => 'static',
'style' => '0',
'module_tag' => 'div',
'bootstrap_size' => '0',
'header_tag' => 'h3',
'header_class' => '',
],
],
[
// Popular Tags
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_9_TITLE'),
'ordering' => 1,
'position' => 'bottom-b',
'module' => 'mod_tags_popular',
'params' => [
'maximum' => 8,
'timeframe' => 'alltime',
'order_value' => 'count',
'order_direction' => 1,
'display_count' => 1,
'no_results_text' => 0,
'minsize' => 1,
'maxsize' => 2,
'layout' => '_:cloud',
'owncache' => 1,
'module_tag' => 'aside',
'bootstrap_size' => 4,
'header_tag' => 'h3',
'style' => 0,
],
],
[
// Similar Items
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_10_TITLE'),
'ordering' => 0,
'module' => 'mod_tags_similar',
'position' => 'bottom-b',
'params' => [
'maximum' => 5,
'matchtype' => 'any',
'layout' => '_:default',
'owncache' => 1,
'module_tag' => 'div',
'bootstrap_size' => 4,
'header_tag' => 'h3',
'style' => 0,
],
],
[
// Backend - Site Information
'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_11_TITLE'),
'ordering' => 4,
'position' => 'cpanel',
'module' => 'mod_stats_admin',
'access' => 6,
'client_id' => 1,
'params' => [
'serverinfo' => 1,
'siteinfo' => 1,
'counter' => 0,
'increase' => 0,
'layout' => '_:default',
'cache' => 1,
'cache_time' => 900,
'cachemode' => 'static',
'module_tag' => 'div',
'bootstrap_size' => 0,
'header_tag' => 'h3',
'style' => 0,
],
],
];
// Assignment means always "only on the homepage".
if (Multilanguage::isEnabled()) {
$homes = Multilanguage::getSiteHomePages();
if (isset($homes[$language])) {
$home = $homes[$language]->id;
}
}
if (!isset($home)) {
$home = $this->getApplication()->getMenu('site')->getDefault()->id;
}
foreach ($modules as $module) {
// Append language suffix to title.
$module['title'] .= $langSuffix;
// Set values which are always the same.
$module['id'] = 0;
$module['asset_id'] = 0;
$module['language'] = $language;
$module['note'] = '';
$module['published'] = 1;
if (!isset($module['assignment'])) {
$module['assignment'] = 0;
} else {
$module['assigned'] = [$home];
}
if (!isset($module['content'])) {
$module['content'] = '';
}
if (!isset($module['access'])) {
$module['access'] = $access;
}
if (!isset($module['showtitle'])) {
$module['showtitle'] = 1;
}
if (!isset($module['client_id'])) {
$module['client_id'] = 0;
}
if (!$model->save($module)) {
$response = [];
$response['success'] = false;
$response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 3, $this->getApplication()->getLanguage()->_($model->getError()));
$event->addResult($response);
return;
}
}
// Get previously entered categories ids
$menuIdsLevel1 = $this->getApplication()->getUserState('sampledata.blog.menuIdsLevel1');
// Get the login modules there could be more than one
$MVCFactory = $this->getApplication()->bootComponent('com_modules')->getMVCFactory();
$modelModules = $MVCFactory->createModel('Modules', 'Administrator', ['ignore_request' => true]);
$modelModules->setState('filter.module', 'mod_login');
$modelModules->setState('filter.client_id', 1);
$loginModules = $modelModules->getItems();
if (!empty($loginModules)) {
$modelModule = $MVCFactory->createModel('Module', 'Administrator', ['ignore_request' => true]);
foreach ($loginModules as $loginModule) {
$lm = (array) $loginModule;
// Un-assign the module from login view, to avoid 403 error
$lm['assignment'] = 1;
$loginId = - (int) $menuIdsLevel1[2];
$lm['assigned'] = [$loginId];
if (!$modelModule->save($lm)) {
$response = [];
$response['success'] = false;
$response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 3, $this->getApplication()->getLanguage()->_($model->getError()));
$event->addResult($response);
return;
}
}
}
$response = [];
$response['success'] = true;
$response['message'] = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_STEP3_SUCCESS');
$event->addResult($response);
}
/**
* Final step to show completion of sampledata.
*
* @param AjaxEvent $event Event instance
*
* @return void
*
* @since 4.0.0
*/
public function onAjaxSampledataApplyStep4(AjaxEvent $event): void
{
if ($this->getApplication()->getInput()->get('type') != $this->_name) {
return;
}
$response['success'] = true;
$response['message'] = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_STEP4_SUCCESS');
$event->addResult($response);
}
/**
* Adds menuitems.
*
* @param array $menuItems Array holding the menuitems arrays.
* @param integer $level Level in the category tree.
*
* @return array IDs of the inserted menuitems.
*
* @since 3.8.0
*
* @throws \Exception
*/
private function addMenuItems(array $menuItems, $level)
{
$itemIds = [];
$access = (int) $this->getApplication()->get('access', 1);
$user = $this->getApplication()->getIdentity();
// Detect language to be used.
$language = Multilanguage::isEnabled() ? $this->getApplication()->getLanguage()->getTag() : '*';
$langSuffix = ($language !== '*') ? ' (' . $language . ')' : '';
// Disable language debug to prevent debug_lang_const being added to the string
$this->getApplication()->getLanguage()->setDebug(false);
foreach ($menuItems as $menuItem) {
// Reset item.id in model state.
$this->menuItemModel->setState('item.id', 0);
// Set values which are always the same.
$menuItem['id'] = 0;
$menuItem['created_user_id'] = $user->id;
$menuItem['alias'] = ApplicationHelper::stringURLSafe($menuItem['title']);
// Set unicodeslugs if alias is empty
if (trim(str_replace('-', '', $menuItem['alias']) == '')) {
$unicode = $this->getApplication()->set('unicodeslugs', 1);
$menuItem['alias'] = ApplicationHelper::stringURLSafe($menuItem['title']);
$this->getApplication()->set('unicodeslugs', $unicode);
}
// Append language suffix to title.
$menuItem['title'] .= $langSuffix;
$menuItem['published'] = 1;
$menuItem['language'] = $language;
$menuItem['note'] = '';
$menuItem['img'] = '';
$menuItem['associations'] = [];
$menuItem['client_id'] = 0;
$menuItem['level'] = $level;
$menuItem['home'] = 0;
// Set browserNav to default if not set
if (!isset($menuItem['browserNav'])) {
$menuItem['browserNav'] = 0;
}
// Set access to default if not set
if (!isset($menuItem['access'])) {
$menuItem['access'] = $access;
}
// Set type to 'component' if not set
if (!isset($menuItem['type'])) {
$menuItem['type'] = 'component';
}
// Set template_style_id to global if not set
if (!isset($menuItem['template_style_id'])) {
$menuItem['template_style_id'] = 0;
}
// Set parent_id to root (1) if not set
if (!isset($menuItem['parent_id'])) {
$menuItem['parent_id'] = 1;
}
if (!$this->menuItemModel->save($menuItem)) {
// Try two times with another alias (-1 and -2).
$menuItem['alias'] .= '-1';
if (!$this->menuItemModel->save($menuItem)) {
$menuItem['alias'] = substr_replace($menuItem['alias'], '2', -1);
if (!$this->menuItemModel->save($menuItem)) {
throw new \Exception($menuItem['title'] . ' => ' . $menuItem['alias'] . ' : ' . $this->menuItemModel->getError());
}
}
}
// Get ID from menuitem we just added
$itemIds[] = $this->menuItemModel->getState('item.id');
}
return $itemIds;
}
}
The same content is in 19 releases, Joomla 5.3.0-beta1 to 6.0.0-alpha2. See them all, or every version of this file.