Model/Config/Source/Settings/Addressbooks.php
public function toOptionArray()
    {
        $fields = [];
        // Add a "Do Not Map" Option
        $fields[] = ['value' => 0, 'label' => '-- Please Select --'];

        $apiEnabled = $this->helper->isEnabled($this->helper->getWebsite());
        if ($apiEnabled) {
            $savedAddressbooks = $this->registry->registry('addressbooks');

            if ($savedAddressbooks) {
                $addressBooks = $savedAddressbooks;
            } else {
                $client = $this->helper->getWebsiteApiClient($this->helper->getWebsite());
                //make an api call an register the addressbooks
                $addressBooks = $client->getAddressBooks();
                if ($addressBooks) {
                    $this->registry->unregister('addressbooks'); // additional measure
                    $this->registry->register('addressbooks', $addressBooks);
                }
            }

            //set up fields with book id and label
            foreach ($addressBooks as $book) {
                if (isset($book->id)) {
                    $fields[] = [
                        'value' => (string)$book->id,
                        'label' => (string)$book->name,
                    ];
                }
            }
        }

        return $fields;
    }
public function toOptionArray()
    {
        $fields = [];
        // Add a "Do Not Map" Option
        $fields[] = ['value' => 0, 'label' => '-- Please Select --'];

        $apiEnabled = $this->helper->isEnabled($this->helper->getWebsite());
        if ($apiEnabled) {
            $savedAddressbooks = $this->registry->registry('addressbooks');

            if ($savedAddressbooks) {
                $addressBooks = $savedAddressbooks;
            } else {
                $client = $this->helper->getWebsiteApiClient($this->helper->getWebsite());
                //make an api call an register the addressbooks
                $addressBooks = $client->getAddressBooks();
                if ($addressBooks) {
                    $this->registry->unregister('addressbooks'); // additional measure
                    $this->registry->register('addressbooks', $addressBooks);
                }
            }

            //set up fields with book id and label
            foreach ($addressBooks as $book) {
                if (isset($book->id)) {
                    $fields[] = [
                        'value' => (string)$book->id,
                        'label' => (string)$book->name,
                    ];
                }
            }
        }

        return $fields;
    }
public function toOptionArray ( ) { $ fields = [ ] ; // Add a "Do Not Map" Option $ fields [ ] = [ 'value' => 0 , 'label' => '-- Please Select --' ] ; $ apiEnabled = $ this -> helper -> isEnabled ( $ this -> helper -> getWebsite ( ) ) ; if ( $ apiEnabled ) { $ savedAddressbooks = $ this -> registry -> registry ( 'addressbooks' ) ; if ( $ savedAddressbooks ) { $ addressBooks = $ savedAddressbooks ; } else { $ client = $ this -> helper -> getWebsiteApiClient ( $ this -> helper -> getWebsite ( ) ) ; //make an api call an register the addressbooks $ addressBooks = $ client -> getAddressBooks ( ) ; if ( $ addressBooks ) { $ this -> registry -> unregister ( 'addressbooks' ) ; // additional measure $ this -> registry -> register ( 'addressbooks' , $ addressBooks ) ; } } //set up fields with book id and label foreach ( $ addressBooks as $ book ) { if ( isset ( $ book -> id ) ) { $ fields [ ] = [ 'value' => ( string ) $ book -> id , 'label' => ( string ) $ book -> name , ] ; } } } return $ fields ; }
Retrieve list of options.

@return array
Retrieve list of options .