vendor/contao-bootstrap/grid/src/Component/ContentElement/GridStopElementController.php line 18

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace ContaoBootstrap\Grid\Component\ContentElement;
  4. use Contao\ContentModel;
  5. use Contao\CoreBundle\ServiceAnnotation\ContentElement;
  6. use Contao\Model;
  7. use ContaoBootstrap\Grid\Exception\GridNotFound;
  8. use ContaoBootstrap\Grid\GridIterator;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use function assert;
  12. /** @ContentElement("bs_gridStop", category="bs_grid") */
  13. final class GridStopElementController extends AbstractGridElementController
  14. {
  15.     /** {@inheritDoc} */
  16.     protected function preGenerate(Request $requestModel $modelstring $section, ?array $classes null): ?Response
  17.     {
  18.         assert($model instanceof ContentModel);
  19.         if (! $this->isBackendRequest($request)) {
  20.             $iterator $this->getIterator($model);
  21.             if ($iterator) {
  22.                 $iterator->rewind();
  23.             }
  24.             return null;
  25.         }
  26.         return $this->renderContentBackendView($this->getParent($model));
  27.     }
  28.     /**
  29.      * Get the parent model.
  30.      */
  31.     protected function getParent(ContentModel $model): ?ContentModel
  32.     {
  33.         return ContentModel::findByPk($model->bs_grid_parent);
  34.     }
  35.     protected function getIterator(ContentModel $model): ?GridIterator
  36.     {
  37.         $provider $this->getGridProvider();
  38.         $parent   $this->getParent($model);
  39.         if ($parent) {
  40.             try {
  41.                 $iterator $provider->getIterator('ce:' $parent->id, (int) $parent->bs_grid);
  42.                 $this->tagResponse('contao.db.tl_bs_grid.' $parent->bs_grid);
  43.                 return $iterator;
  44.             } catch (GridNotFound $e) {
  45.                 // Do nothing. In backend view an error is shown anyway.
  46.                 return null;
  47.             }
  48.         }
  49.         return null;
  50.     }
  51. }