Skip to content

Instantly share code, notes, and snippets.

View alexander-schranz's full-sized avatar

Alexander Schranz alexander-schranz

View GitHub Profile
@alexander-schranz
alexander-schranz / JsFragmentRenderer.php
Created November 8, 2016 08:51
JsFragmentRenderer to load a fragment over ajax instead of esi
<?php
namespace AppBundle\Fragment;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Controller\ControllerReference;
use Symfony\Component\HttpKernel\Fragment\RoutableFragmentRenderer;
use Symfony\Component\HttpKernel\UriSigner;
@alexander-schranz
alexander-schranz / SuluMediaImport.php
Last active November 28, 2016 08:12
SuluMediaImport.php
<?php
$uploadedFile = new UploadedFile(
$filePath, $name, $mimeType, $size
);
$media = $this->getContainer()->get('sulu_media.media_manager')->save(
$uploadedFile,
[
'locale' => $locale,
@alexander-schranz
alexander-schranz / CacheController.php
Last active December 23, 2016 16:23
Cross CacheController.php
<?php
namespace AppBundle\Controller;
use Guzzle\Http\Client;
use Sulu\Bundle\WebsiteBundle\Controller\CacheController as SuluCacheController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
@alexander-schranz
alexander-schranz / basic.html
Last active April 20, 2017 08:14
Basic.html
<!doctype html>
<html lang="de">
<head>
<link rel="stylesheet" href="your.css" />
</head>
<body>
<h1>H1 <br/>Headline</h1>
<p>
Normal Text<br/>
@alexander-schranz
alexander-schranz / smart-content-ajax-loading.html.twig
Last active May 13, 2021 09:02
How to create a overview with ajax loaded pagination user and seo friendly in sulu with smart content.
{# How to create a smart content overview with pagination and ajax loading user and seo friendly in sulu.
#
# Investigate some time and read this article:
# https://webmasters.googleblog.com/2014/02/infinite-scroll-search-friendly.html
#
# See image in the comment for structure.
#
# If you have none smart content elements to pagination (elements loaded in a custom controller)
# replace the following parameters in the twig template with your attributes:
#
@alexander-schranz
alexander-schranz / test-case.patch
Created September 27, 2017 09:43
Sulu Sample Test Case Setup
diff --git a/tests/Functional/AbstractAppTestCase.php b/tests/Functional/AbstractAppTestCase.php
new file mode 100644
index 0000000..a45faab
--- /dev/null
+++ b/tests/Functional/AbstractAppTestCase.php
@@ -0,0 +1,117 @@
+<?php
+
+namespace Tests\Functional;
+
@alexander-schranz
alexander-schranz / AppExtension.php
Created July 24, 2018 09:57
Automatic versioning update on npm run build
<?php
namespace AppBundle\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
@alexander-schranz
alexander-schranz / NavigationTwigExtension.php
Last active May 27, 2024 08:46
CacheNavigationTwigExtension
<?php
namespace App\Twig;
use Doctrine\Common\Cache\CacheProvider;
use Sulu\Bundle\WebsiteBundle\Navigation\NavigationItem;
use Sulu\Bundle\WebsiteBundle\Navigation\NavigationMapperInterface;
use Sulu\Bundle\WebsiteBundle\Twig\Navigation\NavigationTwigExtension as SuluNavigationTwigExtension;
use Sulu\Component\Content\Mapper\ContentMapperInterface;
use Sulu\Component\Webspace\Analyzer\RequestAnalyzerInterface;
@alexander-schranz
alexander-schranz / jackrabbit-phpcr-export-import.sh
Last active March 19, 2019 14:46
jackrabbit-phpcr-export-import
# Export
bin/adminconsole doctrine:phpcr:workspace:export --path /jcr:versions versions.xml
bin/adminconsole doctrine:phpcr:workspace:export --path /cmf admin.xml
bin/websiteconsole doctrine:phpcr:workspace:export --path /cmf website.xml
# In some cases you maybe need to create the phpcr node types and remove then the exist nodes before the import:
bin/adminconsole sulu:document:init
bin/adminconsole doctrine:phpcr:node:remove /cmf
bin/websiteconsole doctrine:phpcr:node:remove /cmf
bin/adminconsole doctrine:phpcr:node:remove /jcr:versions
@alexander-schranz
alexander-schranz / MigrationTest.php
Last active February 14, 2021 18:46
Doctrine Migration TestCase which execute down and up for all migrations
<?php
declare(strict_types=1);
namespace App\Tests\Functional\Migration;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Finder\Finder;