Created
November 11, 2014 22:57
-
-
Save jhartman86/e2a279a5d8a4edca2442 to your computer and use it in GitHub Desktop.
Concrete5.7 Package Controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Concrete\Package\Focal; | |
use Loader; | |
use Package; | |
use PageType; | |
use PageTemplate; | |
use Concrete\Core\Page\Theme\Theme; | |
use Concrete\Core\Page\Type\PublishTarget\Type as PublishTargetType; | |
defined('C5_EXECUTE') or die(_("Access Denied.")); | |
class Controller extends Package { | |
protected $pkgHandle = 'focal'; | |
protected $appVersionRequired = '5.7'; | |
protected $pkgVersion = '0.3'; | |
/** @return string */ | |
public function getPackageName(){ | |
return t('Focal'); | |
} | |
/** @return string */ | |
public function getPackageDescription(){ | |
return t('Focal site package'); | |
} | |
/** @return void */ | |
public function uninstall(){ | |
parent::uninstall(); | |
} | |
/** @return void */ | |
public function install(){ | |
parent::install(); | |
$this->installOrUpdate(); | |
} | |
/** @return void */ | |
public function upgrade(){ | |
parent::upgrade(); | |
$this->installOrUpdate(); | |
} | |
/** | |
* Handle both install and update tasks. Easier to keep everything | |
* in sync. | |
* @return void | |
*/ | |
protected function installOrUpdate(){ | |
$this->pkgTemplates( $this->packageObject() ) | |
->pkgPageTypes( $this->packageObject() ) | |
->pkgThemes( $this->packageObject() ); | |
} | |
/** | |
* @param Package $packageObj | |
* @return Controller $this | |
*/ | |
protected function pkgThemes( Package $packageObj ){ | |
Theme::add('focalize', $packageObj); | |
return $this; | |
} | |
/** | |
* @param Package $packageObj | |
* @return Controller $this | |
*/ | |
protected function pkgTemplates( Package $packageObj ){ | |
if( ! PageTemplate::getByHandle('article') ){ | |
PageTemplate::add('article', t('Article'), 'full.png', $packageObj); | |
} | |
return $this; | |
} | |
/** | |
* @param Package $packageObj | |
* @return Controller $this | |
*/ | |
protected function pkgPageTypes( Package $packageObj ){ | |
if( !(PageType::getByHandle('article')) ){ | |
$ptArticle = PageType::add(array( | |
'handle' => 'article', | |
'name' => t('Article'), | |
'defaultTemplate' => PageTemplate::getByHandle('article'), | |
'ptIsFrequentlyAdded' => 1, | |
'ptLaunchInComposer' => 1 | |
), $packageObj); | |
// PublishTargetType has a getByHandle method to return instance types | |
// in /web/concrete/src/Page/Type/PublishTarget/Type | |
$target = PublishTargetType\Type::getByHandle('all'); | |
$targetConfig = $target->configurePageTypePublishTarget($ptArticle, array( | |
'ptID' => $ptArticle->getPageTypeID() | |
)); | |
// Set configured publish target | |
$ptArticle->setConfiguredPageTypePublishTargetObject($targetConfig); | |
} | |
return $this; | |
} | |
/** | |
* Memoize the package object instance. | |
* @return mixed Package | null | |
*/ | |
private function packageObject(){ | |
if( $this->_packageObj === null ){ | |
$this->_packageObj = Package::getByHandle($this->pkgHandle); | |
} | |
return $this->_packageObj; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment