-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from zoglo/main
Unlock Contao 5 / Symfony Bundle structure
- Loading branch information
Showing
20 changed files
with
191 additions
and
173 deletions.
There are no files selected for viewing
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,19 @@ | ||
# top-most EditorConfig file | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.{php,twig,yaml,yml}] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[*.{html5,svg,min.css,min.js}] | ||
insert_final_newline = false | ||
|
||
[*.html5] | ||
indent_style = space | ||
indent_size = 2 |
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,2 @@ | ||
/.gitignore export-ignore | ||
/assets export-ignore |
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,3 @@ | ||
# Composer | ||
/composer.lock | ||
/vendor/ |
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 |
---|---|---|
@@ -1,3 +1,14 @@ | ||
# Contao Inhaltselemente verlinken | ||
<h1 align="center">Contao Linked Elements</h1> | ||
<div align="center"> | ||
<img src="assets/readme/linkElement.png"> | ||
</div> | ||
|
||
Nach der Installation, kann jedes Inhaltselement verlinkt werden. | ||
--- | ||
|
||
> Working with **Contao 4.13** and **Contao 5+** (PHP ^8.1) | ||
--- | ||
|
||
## Description | ||
|
||
Allows linking every content element by wrapping the content with an `<a>` tag |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,33 +1,33 @@ | ||
{ | ||
"name": "sioweb/linkedelement", | ||
"type": "contao-bundle", | ||
"description": "LinkedElement for Contao 4", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Sascha Weidner", | ||
"email": "support@sioweb.de" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.5.0", | ||
"contao/core-bundle": "^4" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Sioweb\\LinkedElementBundle\\": "src/" | ||
}, | ||
"classmap": [ | ||
"src/Resources/contao/" | ||
], | ||
"exclude-from-classmap": [ | ||
"src/Resources/contao/config/", | ||
"src/Resources/contao/dca/", | ||
"src/Resources/contao/languages/", | ||
"src/Resources/contao/templates/" | ||
] | ||
}, | ||
"extra": { | ||
"contao-manager-plugin": "Sioweb\\LinkedElementBundle\\ContaoManager\\Plugin" | ||
"name": "sioweb/linkedelement", | ||
"type": "contao-bundle", | ||
"description": "LinkedElement for Contao 4", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Sascha Weidner", | ||
"email": "support@sioweb.de" | ||
} | ||
], | ||
"require": { | ||
"php": "^8.1", | ||
"contao/core-bundle": "^4.13 || ^5.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Sioweb\\LinkedElementBundle\\": "src/" | ||
}, | ||
"classmap": [ | ||
"contao/" | ||
], | ||
"exclude-from-classmap": [ | ||
"contao/config/", | ||
"contao/dca/", | ||
"contao/languages/", | ||
"contao/templates/" | ||
] | ||
}, | ||
"extra": { | ||
"contao-manager-plugin": "Sioweb\\LinkedElementBundle\\ContaoManager\\Plugin" | ||
} | ||
} |
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,9 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: true | ||
|
||
Sioweb\LinkedElementBundle\: | ||
resource: '../src/' | ||
exclude: '../src/{DependencyInjection}' |
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @author Sascha Weidner <https://www.sioweb.de> | ||
* @copyright Sioweb, Sascha Weidner | ||
*/ | ||
|
||
use Contao\CoreBundle\DataContainer\PaletteManipulator; | ||
|
||
// Extend the default palettes | ||
$objPalette = PaletteManipulator::create() | ||
->addField(['linkedElement', 'linkedElementTarget'], 'type_legend', PaletteManipulator::POSITION_APPEND) | ||
->applyToPalette('default', 'tl_content') | ||
; | ||
|
||
foreach ($GLOBALS['TL_DCA']['tl_content']['palettes'] as $name => $palette) | ||
{ | ||
if (!is_array($palette)) | ||
{ | ||
$objPalette->applyToPalette($name, 'tl_content'); | ||
} | ||
} | ||
|
||
$GLOBALS['TL_DCA']['tl_content']['fields']['linkedElement'] = [ | ||
'exclude' => true, | ||
'search' => true, | ||
'inputType' => 'text', | ||
'eval' => ['rgxp' => 'url', 'decodeEntities' => true, 'maxlength' => 2048, 'dcaPicker' => true, 'tl_class' => 'w50'], | ||
'sql' => "varchar(2048) NOT NULL default ''" | ||
]; | ||
|
||
$GLOBALS['TL_DCA']['tl_content']['fields']['linkedElementTarget'] = $GLOBALS['TL_DCA']['tl_content']['fields']['target']; |
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,5 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
$GLOBALS['TL_LANG']['tl_content']['linkedElement'] = ['Element verlinken', 'Verlinkt das gesamte Element.']; |
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,5 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
$GLOBALS['TL_LANG']['tl_content']['linkedElement'] = ['Link element', 'Links the entire element.']; |
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,3 @@ | ||
<a href="<?= $this->linkedElement; ?>" class="ce_linkedElement block"<?= $this->linkedElementTarget ? ' target="_blank"' : '' ?>> | ||
<?= $this->element; ?> | ||
</a> |
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 |
---|---|---|
@@ -1,28 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sioweb\LinkedElementBundle\ContaoManager; | ||
|
||
use Contao\CoreBundle\ContaoCoreBundle; | ||
use Contao\ManagerPlugin\Bundle\Config\BundleConfig; | ||
use Contao\ManagerPlugin\Bundle\BundlePluginInterface; | ||
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface; | ||
|
||
/** | ||
* Plugin for the Contao Manager. | ||
* | ||
* @author Sascha Weidner <https://www.sioweb.de> | ||
*/ | ||
use Sioweb\LinkedElementBundle\SiowebLinkedElementBundle; | ||
|
||
class Plugin implements BundlePluginInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getBundles(ParserInterface $parser) | ||
{ | ||
return [ | ||
BundleConfig::create('Sioweb\LinkedElementBundle\SiowebLinkedElementBundle') | ||
->setLoadAfter(['Contao\CoreBundle\ContaoCoreBundle']) | ||
->setReplace(['sioweblinkedelement']), | ||
BundleConfig::create(SiowebLinkedElementBundle::class) | ||
->setReplace(['sioweblinkedelement']) | ||
->setLoadAfter([ContaoCoreBundle::class]) | ||
]; | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sioweb\LinkedElementBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Extension\Extension; | ||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; | ||
|
||
class SiowebLinkedElementExtension extends Extension | ||
{ | ||
public function load(array $configs, ContainerBuilder $container): void | ||
{ | ||
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../../config')); | ||
$loader->load('services.yaml'); | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sioweb\LinkedElementBundle\EventListener; | ||
|
||
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook; | ||
use Contao\ContentElement; | ||
use Contao\ContentModel; | ||
use Contao\FrontendTemplate; | ||
|
||
#[AsHook('getContentElement')] | ||
class GetContentElementListener | ||
{ | ||
public function __invoke(ContentModel $contentModel, string $buffer, $element): string | ||
{ | ||
if ($contentModel->linkedElement) | ||
{ | ||
$template = new FrontendTemplate('ce_linkedElement'); | ||
$template->setData($contentModel->row()); | ||
$template->element = preg_replace('/<a([^>]*)>([^<]*)\<\/a>/is', '<span$1>$2</span>', $buffer); | ||
|
||
// @todo Use one regex: ( href="[^"]*"| target="[^"]*"| name="[^"]*"| rel="[^"]*") | ||
$template->element = preg_replace('/<span([^h]*)href[^=]*=[^"]*"[^"]*"([^>]*)>/is', '<span$1$2>', $template->element); | ||
$template->element = preg_replace('/<span([^h]*)name[^=]*=[^"]*"[^"]*"([^>]*)>/is', '<span$1$2>', $template->element); | ||
$template->element = preg_replace('/<span([^h]*)target[^=]*=[^"]*"[^"]*"([^>]*)>/is', '<span$1$2>', $template->element); | ||
$template->element = preg_replace('/<span([^h]*)rel[^=]*=[^"]*"[^"]*"([^>]*)>/is', '<span$1$2>', $template->element); | ||
|
||
$buffer = $template->parse(); | ||
} | ||
|
||
return $buffer; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.