-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Introduce blog categories (#142)
The behavior of blog categories is now streamlined with categories that can be selected within the page records. Without touching or limiting normal categories. Blog categories only show other blog categories within the parent selector box, that are created in the same directory.
- Loading branch information
1 parent
a3061fe
commit 434a50e
Showing
11 changed files
with
346 additions
and
55 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
Classes/Backend/FormDataProvider/CategoryDefaultValueProvider.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
/* | ||
* This file is part of the package t3g/blog. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace T3G\AgencyPack\Blog\Backend\FormDataProvider; | ||
|
||
use T3G\AgencyPack\Blog\Constants; | ||
use TYPO3\CMS\Backend\Form\FormDataProviderInterface; | ||
|
||
class CategoryDefaultValueProvider implements FormDataProviderInterface | ||
{ | ||
public function addData(array $result): array | ||
{ | ||
if ($result['command'] !== 'new' || | ||
$result['tableName'] !== 'sys_category' || | ||
$result['parentPageRow']['module'] !== 'blog') { | ||
return $result; | ||
} | ||
|
||
$result['databaseRow']['record_type'][0] = (string) Constants::CATEGORY_TYPE_BLOG; | ||
$result['recordTypeValue'] = (string) Constants::CATEGORY_TYPE_BLOG; | ||
|
||
return $result; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
/* | ||
* This file is part of the package t3g/blog. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace T3G\AgencyPack\Blog\Updates; | ||
|
||
use T3G\AgencyPack\Blog\Constants; | ||
use TYPO3\CMS\Core\Database\Connection; | ||
use TYPO3\CMS\Core\Database\ConnectionPool; | ||
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Install\Updates\DatabaseUpdatedPrerequisite; | ||
use TYPO3\CMS\Install\Updates\UpgradeWizardInterface; | ||
|
||
/** | ||
* CategoryTypeUpdate | ||
*/ | ||
class CategoryTypeUpdate implements UpgradeWizardInterface | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function getIdentifier(): string | ||
{ | ||
return self::class; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getTitle(): string | ||
{ | ||
return '[EXT:blog] Use Blog-Type for Categories'; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getDescription(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getPrerequisites(): array | ||
{ | ||
return [ | ||
DatabaseUpdatedPrerequisite::class | ||
]; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function updateNecessary(): bool | ||
{ | ||
$queryBuilderPages = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages'); | ||
$queryBuilderPages->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class)); | ||
$pagesStatement = $queryBuilderPages | ||
->select('uid') | ||
->from('pages') | ||
->where( | ||
$queryBuilderPages->expr()->andX( | ||
$queryBuilderPages->expr()->eq('doktype', $queryBuilderPages->createNamedParameter(254, \PDO::PARAM_INT)), | ||
$queryBuilderPages->expr()->eq('module', $queryBuilderPages->createNamedParameter('blog')) | ||
) | ||
) | ||
->execute(); | ||
$pages = []; | ||
while ($pageRecord = $pagesStatement->fetch()) { | ||
$pages[] = $pageRecord['uid']; | ||
} | ||
|
||
$queryBuilderCategories = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_category'); | ||
$queryBuilderCategories->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class)); | ||
$elementCount = $queryBuilderCategories | ||
->count('uid') | ||
->from('sys_category') | ||
->where( | ||
$queryBuilderCategories->expr()->andX( | ||
$queryBuilderCategories->expr()->eq('record_type', $queryBuilderCategories->createNamedParameter(1, \PDO::PARAM_INT)), | ||
$queryBuilderCategories->expr()->in('pid', $queryBuilderCategories->createNamedParameter($pages, Connection::PARAM_INT_ARRAY)) | ||
) | ||
) | ||
->execute() | ||
->fetchColumn(0); | ||
|
||
return (bool)$elementCount; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function executeUpdate(): bool | ||
{ | ||
$queryBuilderPages = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages'); | ||
$queryBuilderPages->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class)); | ||
$pagesStatement = $queryBuilderPages | ||
->select('uid') | ||
->from('pages') | ||
->where( | ||
$queryBuilderPages->expr()->andX( | ||
$queryBuilderPages->expr()->eq('doktype', $queryBuilderPages->createNamedParameter(254, \PDO::PARAM_INT)), | ||
$queryBuilderPages->expr()->eq('module', $queryBuilderPages->createNamedParameter('blog')) | ||
) | ||
) | ||
->execute(); | ||
$pages = []; | ||
while ($pageRecord = $pagesStatement->fetch()) { | ||
$pages[] = $pageRecord['uid']; | ||
} | ||
|
||
$queryBuilderCategories = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_category'); | ||
$queryBuilderCategories->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class)); | ||
$categoryStatement = $queryBuilderCategories | ||
->select('uid', 'record_type') | ||
->from('sys_category') | ||
->where( | ||
$queryBuilderCategories->expr()->andX( | ||
$queryBuilderCategories->expr()->eq('record_type', $queryBuilderCategories->createNamedParameter(Constants::CATEGORY_TYPE_DEFAULT, \PDO::PARAM_INT)), | ||
$queryBuilderCategories->expr()->in('pid', $queryBuilderCategories->createNamedParameter($pages, Connection::PARAM_INT_ARRAY)) | ||
) | ||
) | ||
->execute(); | ||
|
||
while ($categoryRecord = $categoryStatement->fetch()) { | ||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_category'); | ||
$queryBuilder | ||
->update('sys_category') | ||
->where( | ||
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter((int) $categoryRecord['uid'], \PDO::PARAM_INT)) | ||
) | ||
->set('record_type', Constants::CATEGORY_TYPE_BLOG); | ||
$queryBuilder->execute(); | ||
} | ||
|
||
return true; | ||
} | ||
} |
Oops, something went wrong.