examples/AdWords/v201809/Extensions/AddSitelinksUsingFeeds.php
private static function createSitelinksFeedMapping(
        AdWordsServices $adWordsServices,
        AdWordsSession $session,
        array $sitelinksData
    ) {
        $feedMappingService =
            $adWordsServices->get($session, FeedMappingService::class);

        // Map the feed attribute IDs to the field ID constants.
        $linkTextFieldMapping = new AttributeFieldMapping();
        $linkTextFieldMapping->setFeedAttributeId(
            $sitelinksData['linkTextFeedAttributeId']
        );
        $linkTextFieldMapping->setFieldId(
            self::PLACEHOLDER_FIELD_SITELINK_LINK_TEXT
        );
        $linkFinalUrlFieldMapping = new AttributeFieldMapping();
        $linkFinalUrlFieldMapping->setFeedAttributeId(
            $sitelinksData['linkFinalUrlFeedAttributeId']
        );
        $linkFinalUrlFieldMapping->setFieldId(
            self::PLACEHOLDER_FIELD_SITELINK_FINAL_URL
        );
        $line2FieldMapping = new AttributeFieldMapping();
        $line2FieldMapping->setFeedAttributeId(
            $sitelinksData['line2FeedAttribute']
        );
        $line2FieldMapping->setFieldId(self::PLACEHOLDER_FIELD_LINE_2_TEXT);
        $line3FieldMapping = new AttributeFieldMapping();
        $line3FieldMapping->setFeedAttributeId(
            $sitelinksData['line3FeedAttribute']
        );
        $line3FieldMapping->setFieldId(self::PLACEHOLDER_FIELD_LINE_3_TEXT);

        // Create the feed mapping and feed mapping operation.
        $feedMapping = new FeedMapping();
        $feedMapping->setPlaceholderType(self::PLACEHOLDER_SITELINKS);
        $feedMapping->setFeedId($sitelinksData['sitelinksFeedId']);
        $feedMapping->setAttributeFieldMappings(
            [
                $linkTextFieldMapping,
                $linkFinalUrlFieldMapping,
                $line2FieldMapping,
                $line3FieldMapping
            ]
        );

        $operation = new FeedMappingOperation();
        $operation->setOperand($feedMapping);
        $operation->setOperator(Operator::ADD);

        // Create the feed mapping operation on the server and print out some
        // information.
        $result = $feedMappingService->mutate([$operation]);
        foreach ($result->getValue() as $feedMapping) {
            printf(
                'Feed mapping with ID %d and placeholder type %d was '
                . 'saved for feed with ID %d.%s',
                $feedMapping->getFeedMappingId(),
                $feedMapping->getPlaceholderType(),
                $feedMapping->getFeedId(),
                PHP_EOL
            );
        }
    }
private static function createSitelinksFeedMapping(
        AdWordsServices $adWordsServices,
        AdWordsSession $session,
        array $sitelinksData
    ) {
        $feedMappingService =
            $adWordsServices->get($session, FeedMappingService::class);

        // Map the feed attribute IDs to the field ID constants.
        $linkTextFieldMapping = new AttributeFieldMapping();
        $linkTextFieldMapping->setFeedAttributeId(
            $sitelinksData['linkTextFeedAttributeId']
        );
        $linkTextFieldMapping->setFieldId(
            self::PLACEHOLDER_FIELD_SITELINK_LINK_TEXT
        );
        $linkFinalUrlFieldMapping = new AttributeFieldMapping();
        $linkFinalUrlFieldMapping->setFeedAttributeId(
            $sitelinksData['linkFinalUrlFeedAttributeId']
        );
        $linkFinalUrlFieldMapping->setFieldId(
            self::PLACEHOLDER_FIELD_SITELINK_FINAL_URL
        );
        $line2FieldMapping = new AttributeFieldMapping();
        $line2FieldMapping->setFeedAttributeId(
            $sitelinksData['line2FeedAttribute']
        );
        $line2FieldMapping->setFieldId(self::PLACEHOLDER_FIELD_LINE_2_TEXT);
        $line3FieldMapping = new AttributeFieldMapping();
        $line3FieldMapping->setFeedAttributeId(
            $sitelinksData['line3FeedAttribute']
        );
        $line3FieldMapping->setFieldId(self::PLACEHOLDER_FIELD_LINE_3_TEXT);

        // Create the feed mapping and feed mapping operation.
        $feedMapping = new FeedMapping();
        $feedMapping->setPlaceholderType(self::PLACEHOLDER_SITELINKS);
        $feedMapping->setFeedId($sitelinksData['sitelinksFeedId']);
        $feedMapping->setAttributeFieldMappings(
            [
                $linkTextFieldMapping,
                $linkFinalUrlFieldMapping,
                $line2FieldMapping,
                $line3FieldMapping
            ]
        );

        $operation = new FeedMappingOperation();
        $operation->setOperand($feedMapping);
        $operation->setOperator(Operator::ADD);

        // Create the feed mapping operation on the server and print out some
        // information.
        $result = $feedMappingService->mutate([$operation]);
        foreach ($result->getValue() as $feedMapping) {
            printf(
                'Feed mapping with ID %d and placeholder type %d was '
                . 'saved for feed with ID %d.%s',
                $feedMapping->getFeedMappingId(),
                $feedMapping->getPlaceholderType(),
                $feedMapping->getFeedId(),
                PHP_EOL
            );
        }
    }
private static function createSitelinksFeedMapping ( AdWordsServices $ adWordsServices , AdWordsSession $ session , array $ sitelinksData ) { $ feedMappingService = $ adWordsServices -> get ( $ session , FeedMappingService :: class ) ; // Map the feed attribute IDs to the field ID constants. $ linkTextFieldMapping = new AttributeFieldMapping ( ) ; $ linkTextFieldMapping -> setFeedAttributeId ( $ sitelinksData [ 'linkTextFeedAttributeId' ] ) ; $ linkTextFieldMapping -> setFieldId ( self :: PLACEHOLDER_FIELD_SITELINK_LINK_TEXT ) ; $ linkFinalUrlFieldMapping = new AttributeFieldMapping ( ) ; $ linkFinalUrlFieldMapping -> setFeedAttributeId ( $ sitelinksData [ 'linkFinalUrlFeedAttributeId' ] ) ; $ linkFinalUrlFieldMapping -> setFieldId ( self :: PLACEHOLDER_FIELD_SITELINK_FINAL_URL ) ; $ line2FieldMapping = new AttributeFieldMapping ( ) ; $ line2FieldMapping -> setFeedAttributeId ( $ sitelinksData [ 'line2FeedAttribute' ] ) ; $ line2FieldMapping -> setFieldId ( self :: PLACEHOLDER_FIELD_LINE_2_TEXT ) ; $ line3FieldMapping = new AttributeFieldMapping ( ) ; $ line3FieldMapping -> setFeedAttributeId ( $ sitelinksData [ 'line3FeedAttribute' ] ) ; $ line3FieldMapping -> setFieldId ( self :: PLACEHOLDER_FIELD_LINE_3_TEXT ) ; // Create the feed mapping and feed mapping operation. $ feedMapping = new FeedMapping ( ) ; $ feedMapping -> setPlaceholderType ( self :: PLACEHOLDER_SITELINKS ) ; $ feedMapping -> setFeedId ( $ sitelinksData [ 'sitelinksFeedId' ] ) ; $ feedMapping -> setAttributeFieldMappings ( [ $ linkTextFieldMapping , $ linkFinalUrlFieldMapping , $ line2FieldMapping , $ line3FieldMapping ] ) ; $ operation = new FeedMappingOperation ( ) ; $ operation -> setOperand ( $ feedMapping ) ; $ operation -> setOperator ( Operator :: ADD ) ; // Create the feed mapping operation on the server and print out some // information. $ result = $ feedMappingService -> mutate ( [ $ operation ] ) ; foreach ( $ result -> getValue ( ) as $ feedMapping ) { printf ( 'Feed mapping with ID %d and placeholder type %d was ' . 'saved for feed with ID %d.%s' , $ feedMapping -> getFeedMappingId ( ) , $ feedMapping -> getPlaceholderType ( ) , $ feedMapping -> getFeedId ( ) , PHP_EOL ) ; } }
Maps the feed attributes to the sitelink placeholders.
Maps the feed attributes to the sitelink placeholders .