Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration is only available after saving the tt_content record #1

Open
josefglatz opened this issue Feb 15, 2017 · 1 comment
Open

Comments

@josefglatz
Copy link

No description provided.

@nemstaa
Copy link

nemstaa commented Jan 17, 2018

`<?php
declare(strict_types=1);
namespace Sup7even\ImageCropperConfiguration\Form\Element;
/*

  • This file is part of the TYPO3 CMS project.
  • It is free software; you can redistribute it and/or modify it under
  • the terms of the GNU General Public License, either version 2
  • of the License, or any later version.
  • For the full copyright and license information, please read the
  • LICENSE.txt file that was distributed with this source code.
  • The TYPO3 project - inspiring people to share!
    /
    use TYPO3\CMS\Backend\Utility\BackendUtility;
    use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
    use TYPO3\CMS\Core\Resource\File;
    use TYPO3\CMS\Core\Utility\GeneralUtility;
    use TYPO3\CMS\Core\Utility\MathUtility;
    use TYPO3\CMS\Core\Utility\StringUtility;
    /
    *
  • Generation of image manipulation FormEngine element.
  • This is typically used in FAL relations to cut images.
    /
    class ImageManipulationElement extends \TYPO3\CMS\Backend\Form\Element\ImageManipulationElement
    {
    /
    *
    • @param array $config

    • @param string $elementValue

    • @param File $file

    • @return array

    • @throws \TYPO3\CMS\Core\Imaging\ImageManipulation\InvalidConfigurationException
      */
      protected function processConfiguration(array $config, string &$elementValue, File $file)
      {
      // remove "if ($this->data['command'] !== 'new') {"
      $table = $this->data['inlineParentTableName'] . '.';
      if ($table === 'tt_content.') {
      $uid = $this->data['inlineParentUid'];
      $fullRow = BackendUtility::getRecord('tt_content', $uid, 'CType');
      $subKey = $fullRow['CType'];
      } else {
      $subKey = $this->data['inlineParentFieldName'];
      }
      $subKey .= '.';
      $final = [];
      if (isset($this->data['pageTsConfig']['cropVariants.']) && is_array($this->data['pageTsConfig']['cropVariants.'])) {
      $tsconfig = $this->data['pageTsConfig']['cropVariants.'];
      $relevantConfig = [];
      if (isset($tsconfig[$table])) {
      if (isset($tsconfig[$table][$subKey])) {
      $relevantConfig = $tsconfig[$table][$subKey];
      }
      }
      foreach ($relevantConfig as $variantKey => $variant) {
      $variantKey = rtrim($variantKey, '.');
      $final[$variantKey] = [
      'title' => $variant['title'],
      ];
      if (isset($variant['allowedAspectRatios.']) && is_array($variant['allowedAspectRatios.'])) {
      foreach ($variant['allowedAspectRatios.'] as $key => $ratios) {
      $key = rtrim($key, '.');
      $final[$variantKey]['allowedAspectRatios'][$key]['title'] = $ratios['title'];
      $final[$variantKey]['allowedAspectRatios'][$key]['value'] = $this->calc($ratios['value']);
      }
      }
      if (isset($variant['selectedRatio'])) {
      $final[$variantKey]['selectedRatio'] = $variant['selectedRatio'];
      }
      foreach (['cropArea', 'focusArea'] as $name) {
      $name2 = $name . '.';
      if (isset($variant[$name2])) {
      $final[$variantKey][$name] = $this->getArea($variant[$name2]);
      }
      }
      if (isset($variant['coverAreas.'])) {
      foreach ($variant['coverAreas.'] as $cKey => $cValue) {
      $cKey = rtrim($cKey, '.');
      $final[$variantKey]['coverArea'][$cKey] = $this->getArea($cValue);
      }
      }
      }
      }
      if (!empty($final)) {
      $config['cropVariants'] = $final;
      }

      return parent::processConfiguration($config, $elementValue, $file);
      }
      protected function getArea(array $area)
      {
      $new = [];
      foreach ($area as $k => $v) {
      $new[$k] = (float)MathUtility::calculateWithPriorityToAdditionAndSubtraction($v);
      }
      return $new;
      }
      protected function calc(string $string)
      {
      return MathUtility::calculateWithPriorityToAdditionAndSubtraction($string);
      }
      }`

Regards
Robert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants