Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Hook for getCountries to limit the country list #2819

Closed
markusmilkereit opened this issue Nov 29, 2011 · 8 comments
Closed

Hook for getCountries to limit the country list #2819

markusmilkereit opened this issue Nov 29, 2011 · 8 comments
Assignees
Labels
Milestone

Comments

@markusmilkereit
Copy link

Many internal function (registration) and extensions (countryselect, efg) use the convinient Controller->getCountries() for their country listings / selects. Would be nice to have a hook after

include(TL_ROOT . '/system/config/countries.php');

to edit the list, extension is almost ready (to edit the visible countries from the backend to limit the size of the selectable items).

--- Originally created on January 21st, 2011, at 12:22pm (ID 2819)

@ghost ghost assigned leofeyer Nov 29, 2011
@leofeyer
Copy link
Member

[[WikiIncompleteEn|Incomplete ticket]]

--- Originally created on January 21st, 2011, at 11:13pm

@markusmilkereit
Copy link
Author

Inkomplete bei einem Feature request, hmm, was will er mir damit sagen? ;) Codebeispiel?
Controller->getCountries()

/**
 * Return all counties as array
 * @return array
 */
protected function getCountries()
{
  $return = array();
  $countries = array();
  $arrAux = array();

  $this->loadLanguageFile('countries');
  include(TL_ROOT . '/system/config/countries.php');

  // entweder hier, aus meiner Sicht sinnvoller
  // HOOK: add custom country logic
  if (isset($GLOBALS['TL_HOOKS']['getCountries']) && is_array($GLOBALS['TL_HOOKS']['getCountries']))
  {
    foreach ($GLOBALS['TL_HOOKS']['getCountries'] as $callback)
    {
      $this->import($callback[0]);
      $return = $this->$callback[0]->$callback[1]($countries);

      // so ..
      if(is_array($return) && count($return)>0) 
      {
        $countries = $return;
      }
      // .. oder weniger transparent via Übergabe einer Referenz im Callback-Aufruf
    }  
  }

  foreach ($countries as $strKey=>$strName)
  {
    $arrAux[$strKey] = strlen($GLOBALS['TL_LANG']['CNT'][$strKey]) ? utf8_romanize($GLOBALS['TL_LANG']['CNT'][$strKey]) : $strName;
  }

  asort($arrAux);

  foreach (array_keys($arrAux) as $strKey)
  {
    $return[$strKey] = strlen($GLOBALS['TL_LANG']['CNT'][$strKey]) ? $GLOBALS['TL_LANG']['CNT'][$strKey] : $countries[$strKey];
  }

  // Hook-Logik alternativ hier, wobei ich es schöner finde die rohe Landesliste im Hook zu bearbeiten  
  // und dann die vorhandene Sprach/Sortierlogik drüber laufen zu lassen

  return $return;
}

--- Originally created on January 22nd, 2011, at 02:56pm

@leofeyer
Copy link
Member

Was genau möchtest Du denn an der Länderliste ändern?

--- Originally created on February 3rd, 2011, at 07:11pm

@markusmilkereit
Copy link
Author

Ich habe eine Erweiterung in Beta, mit der man die Länderliste gezielt einschränken kann. Ziel ist eine Auswahl der Länder bereit zu stellen die auch für den Seitenbetreiber interessant sind, nicht immer die komplette Liste. Macht auch Sinn bei Registrierungen (zum Beispiel nur Europa-Adressen zugelassen), countryselect in Formularen etc.

Es geht vor allem drum die Systemfunktionen wie Registrierung sauber beeinflussen zu können, die Länderliste lässt sich aktuell nur über das country-array steuern das nicht vernünftig und updatesicher angepasst werden kann.

--- Originally created on February 3rd, 2011, at 07:18pm

@leofeyer
Copy link
Member

Und das geht nicht mit einem einfachen array_intersect_assoc($this->getCountries(), $arrSelection)?

--- Originally created on February 6th, 2011, at 06:19pm

@markusmilkereit
Copy link
Author

Ich wüsste nicht wie ich damit zum Beispiel für die Registrierung die Länderliste anpassen sollte? Updatesicher, also nicht in der countries.php
Wenn ich hier nur auf dem Schlauch stehe: hilf mir :)

--- Originally created on February 6th, 2011, at 07:07pm

@leofeyer
Copy link
Member

Implementiert in fda1183.

--- Originally created on November 10th, 2011, at 07:11pm

@leofeyer
Copy link
Member

--- Originally completed on November 10th, 2011, at 07:11pm

leofeyer added a commit that referenced this issue Nov 30, 2011
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants