Craft\ImportService::getCustomOption PHP Method

getCustomOption() public method

Get path to fieldtype's custom
public getCustomOption ( string $fieldHandle ) : string
$fieldHandle string
return string
    public function getCustomOption($fieldHandle)
    {
        // If option paths haven't been loaded
        if (!$this->_loadedOptionPaths) {
            // Call hook for all plugins
            $responses = craft()->plugins->call('registerImportOptionPaths');
            // Loop through responses from each plugin
            foreach ($responses as $customPaths) {
                // Append custom paths to master list
                $this->customOptionPaths = array_merge($this->customOptionPaths, $customPaths);
            }
            // Option paths have been loaded
            $this->_loadedOptionPaths = true;
        }
        // If fieldtype has been registered and is not falsey
        if (array_key_exists($fieldHandle, $this->customOptionPaths) && $this->customOptionPaths[$fieldHandle]) {
            // Return specified custom path
            return $this->customOptionPaths[$fieldHandle];
        }
        return false;
    }

Usage Example

 /**
  * @covers ::getCustomOption
  */
 public function testGetCustomOptionShouldReturnOptionWhenFound()
 {
     $fieldHandle = 'handle';
     $option = array('optionkey' => 'optionvalue');
     $mockPluginsService = $this->getMock('Craft\\PluginsService');
     $mockPluginsService->expects($this->any())->method('call')->with('registerImportOptionPaths')->willReturn(array(array($fieldHandle => $option)));
     $this->setComponent(craft(), 'plugins', $mockPluginsService);
     $service = new ImportService();
     $result = $service->getCustomOption($fieldHandle);
     $this->assertSame($option, $result);
 }