Skip to content

Instantly share code, notes, and snippets.

View kunicmarko20's full-sized avatar
🌀

Marko Kunic kunicmarko20

🌀
View GitHub Profile
@kunicmarko20
kunicmarko20 / cd alias
Created December 14, 2016 09:09
Check for active git branch when changing folder
alias cdg=gitdir
gitdir(){
cd $1
count=$(find . -name .git -type d -maxdepth 1 | wc -l)
if [ $count -gt 0 ]; then
git branch
fi
}
@kunicmarko20
kunicmarko20 / LocaleListener.php
Last active December 23, 2022 03:59
Symfony Locale Listener that redirects to default language route if no language has been added instead of 404
<?php
namespace YourBundle\EventListener;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
@kunicmarko20
kunicmarko20 / MigrateImagesCommand.php
Last active January 9, 2023 09:14
Transfer old images into Sonata Media Bundle. This command is used for adding sonata media gallery to new structure from old database.
<?php
namespace YourBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Application\Sonata\MediaBundle\Entity\Media;
use Application\Sonata\MediaBundle\Entity\Gallery;
use Application\Sonata\MediaBundle\Entity\GalleryHasMedia;
@kunicmarko20
kunicmarko20 / Exporter.php
Last active January 30, 2024 08:45
Custom sonata admin export
<?php
/**
* Created by PhpStorm.
* User: markokunic
* Date: 4/21/17
* Time: 3:41 PM
*/
namespace AppBundle\Exporter;
@kunicmarko20
kunicmarko20 / CloneController.php
Created May 4, 2017 16:27
Drupal 8 Clone Nodes
<?php
namespace Drupal\clone_nodes\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Drupal\node\Entity\Node;
class CloneController extends ControllerBase
{
@kunicmarko20
kunicmarko20 / Article.php
Last active November 16, 2023 07:52
Symfony Second Level Cache
<?php
namespace AppBundle\Entity;
/**
* @package AppBundle\Entity
* @ORM\Entity()
* @ORM\Table()
* @ORM\Cache(usage="NONSTRICT_READ_WRITE")
*/
@kunicmarko20
kunicmarko20 / DebugTemplate.php
Created August 1, 2017 08:54
Twig template name in html comments
<?php
namespace AppBundle\Twig;
abstract class DebugTemplate extends \Twig_Template {
public function display(array $context, array $blocks = array())
{
echo '<!-- START: ' . $this->getTemplateName() . ' -->';
@kunicmarko20
kunicmarko20 / Readme.md
Last active May 4, 2022 06:33
Sonata Admin Custom Page

Sonata Admin Custom Page

This example will help you create custom Sonata Admin page and also explain how to make a statistics admin.

You can read more here

@kunicmarko20
kunicmarko20 / ImageProvider.php
Last active May 22, 2024 12:30
Sonata Media SVG Provider
<?php
namespace YourBundle\Provider;
use Sonata\MediaBundle\Provider\FileProvider;
class ImageProvider extends FileProvider
{
}
bendavies [1:22 PM]
@iltar we use this to solve this problem: https://github.com/SyliusLabs/AssociationHydrator
use it like so (edited)
https://github.com/Sylius/Sylius/blob/0205d4b3efa155a05b29bcc64849fd7cd460ceea/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/OrderRepository.php#L300-L313
iltar [1:31 PM]
That will still cause queries, won't it?
bendavies [1:35 PM]
it does what is suggested in ocramius' post